j4ymf Posted August 9, 2009 Share Posted August 9, 2009 hello folks its been some time since ive used php, but in starting to play again. ive got this function and i want to be able to use the $totaltally else where as well so i need to call the function early, but ive forgot where to put the call function. can you please help thanks jason //.....///.......///.........////........../////........///....../////............////.............. function check_team_totaltally($player_1, $player_2, $player_3, $player_4, $player_5, $player_6, $player_7, $player_8, $player_9, $player_10, $player_11) { include("passwords.inc"); $connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $query = "SELECT sum(price) 'total' "; $query .= "FROM dreamteam "; $query .= "WHERE dreamteam.id "; $query .= "IN ('$player_1', '$player_2', '$player_3', '$player_4', '$player_5', '$player_6', '$player_7', '$player_8', '$player_9', '$player_10', '$player_11')"; // echo "<p>check_team_total() >>> " . $query . "<p>"; //(remove the // ehen checking for errors) $result = mysql_query($query) or die ("<font color='#ffff00' size='4'>Error! checking your team total! (3)"); $total = mysql_fetch_assoc($result); if ($total1['total'] > 50) { // change to 40 for normal seasons 50 for the world cup global $totaltally; $totaltally = $total1['total']; return False; } else { return True; } $returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); echo " $totaltally " ; } //.....///.......///.........////........../////........///....../////............////.............. Quote Link to comment https://forums.phpfreaks.com/topic/169440-how-do-i-call-a-function-again/ Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Well, you're doing like $returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); so you could just do $totaltally = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); instead. Also, I would refactor your function to take an array instead of 11 separate elements. Quote Link to comment https://forums.phpfreaks.com/topic/169440-how-do-i-call-a-function-again/#findComment-893963 Share on other sites More sharing options...
j4ymf Posted August 9, 2009 Author Share Posted August 9, 2009 hello daniel thanks for getting back to me, can you send an example, because im still stuck. can you re do my code so i can see what you mean thanks jason Quote Link to comment https://forums.phpfreaks.com/topic/169440-how-do-i-call-a-function-again/#findComment-893970 Share on other sites More sharing options...
wildteen88 Posted August 9, 2009 Share Posted August 9, 2009 This is the code you use to call the function $returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); Use that code to call that function again. However your function can be made a lot better. include("passwords.inc"); $connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); Personally I would have all that in single file called db.php. Whenever you want to connect to MySQL use require_once "db.php" WARNING having code in .inc files can be read as plain text. So if someone found out where your passwords.inc file is by going to yoursite.com/passwords.inc they will be able to read your database credentials. You should end all files in .php to prevent this, ed file.inc.php This is not recommend global $totaltally; $totaltally = $total1['total']; return False; You should change it to return $total1['total']; Quote Link to comment https://forums.phpfreaks.com/topic/169440-how-do-i-call-a-function-again/#findComment-894003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.