j4ymf Posted July 18, 2009 Share Posted July 18, 2009 hello folks its been along time since iv'e been on here, but iv'e just start playing with php again and i would like some help please. // *-----------------------------------------------------------* // * check_team_total() * // * * // * Makes sure that no dreamteam has a value of more than * // * £50 million * // *-----------------------------------------------------------* function check_team_total($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')"; $result = mysql_query($query) or die ("<font color='#ffff00' size='4'>Error! checking your team total! (3)"); $total = mysql_fetch_assoc($result); if ($total['total'] > 50) { // change to 40 for normal seasons 50 for the world cup global $truetotal; $truetotal = $total; return False; } else { return True; } } i need to be able to use $truetotal as a global so i can pull it in a few places.ive added this but i cant get it to work, global $truetotal; $truetotal = $total; please could you get me started again many thanks jason Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/ Share on other sites More sharing options...
Amtran Posted July 18, 2009 Share Posted July 18, 2009 Do you mean: <?php global $truetotal; $total = $truetotal; Otherwise, you're just giving $truetotal the value of $total, so there is no reason to even make $truetotal global. Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877756 Share on other sites More sharing options...
j4ymf Posted July 18, 2009 Author Share Posted July 18, 2009 thanks amtram im not sure what i need!! im looking for some help i need to able to use the value of $total some where else so whats my best way to do it? jason Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877763 Share on other sites More sharing options...
Amtran Posted July 18, 2009 Share Posted July 18, 2009 By somewhere else do you mean in another function, another file, just somewhere different in the same file? Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877769 Share on other sites More sharing options...
j4ymf Posted July 19, 2009 Author Share Posted July 19, 2009 hello amtran in the function it it used for adding up the total and checking if its not above 50 i would like to be able to use it within the same file just call back the total and use it out side that function if you get what i mean. jason Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877840 Share on other sites More sharing options...
Amtran Posted July 19, 2009 Share Posted July 19, 2009 You could have it return the value, instead of True or False. So: if ($total['total'] > 50) { // change to 40 for normal seasons 50 for the world cup global $truetotal; $truetotal = $total; return $truetotal; Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877858 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 The global keyword and the $GLOBALS superglobal variable are both one of the very bad ideas implemented in PHP. Just saying. Learn how to pass things by argument and how to return values from a function. Quote Link to comment https://forums.phpfreaks.com/topic/166450-global-varable/#findComment-877881 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.