FireFrenzy Posted July 22, 2007 Share Posted July 22, 2007 Okay, I know spewing out a myraid of code doesn't help pinpoint problems, so I'll try to be as concise. This is the scores page for a Promisance-like game. I take ranks 1-10, and then use the function again to get 15 ranks above and below the players current rank, per the "getScores" function -- standard stuff. However, what I'm trying to do is display an icon for particular stats, such as most land. However, the MySQL query for that seems bounded by the outer one; it selects the player with the most land from both loops, and displays. Is there any way to prevent this -- to get a query of all players? getScores(0, 10, 'scores1'); getScores($start, $end, 'scores2'); Calls: function getScores($start, $end, $array) { global $playerdb, $$array, $enemy, $ssort, $clause, $query; $limit = "$start,$end"; $scores = mysql_safe_query("SELECT rank,empire,num,land,networth,clan,race,era,online,disabled,turnsused,vacation,kills,offtotal,deftotal FROM $playerdb WHERE $clause $query ORDER BY $ssort LIMIT $limit;"); if (@mysql_num_rows($scores) != 0) { while ($enemy = mysql_fetch_array($scores)) { printScoreLine($$array); } } } Within the "printScoreLine" function is: $topland = ''; if ($enemy[land] == getland()) $topland = "<img src='img/game_icons/resized/land.gif'>"; This calls the function to enable the link: function getLand() { global $playerdb, $enemy; $topland = mysql_fetch_array(mysql_safe_query("SELECT * FROM $playerdb ORDER BY land DESC")); return $topland[land]; } As I said before, the query within the "getLand" function only appears to display results bounded by the query in the first function. I'm sure that there is a way to simplify and solve this...and, well, I guess that's why I'm posting. Unfortunately, my knowledge is quite incomprehensive. Many thanks for any help! Quote Link to comment Share on other sites More sharing options...
Barand Posted July 22, 2007 Share Posted July 22, 2007 You'll find this more efficient that returning the whole table contents just to get one value from the first record. <?php function getLand() { global $playerdb; $topland = mysql_safe_query("SELECT MAX(land) FROM $playerdb "); return mysql_result($topland,0,0); } ?> Several things puzzle me about your getScores() function - why is $array declared global when you are passing it as an argument - why $$array - having bothered to query all that data I would have passed $enemy to the printScore function as an extra argument. You seem to be overusing globals - bad practice Quote Link to comment 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.