note 97641 deleted from control-structures.for by danbrown

From: Date: Fri, 30 Apr 2010 12:10:24 +0000
Subject: note 97641 deleted from control-structures.for by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168815@lists.php.net to get a copy of this message
Note Submitter: stuck ---- I need an objective looked and feel embarassed having to bring this to a board. But here it is. I am running queries which return top ranked result of individuals to be displayed on a records page. This code is returning extra results than what it should. <?php ///////////////////////////////////// //WINS ///////////////////////////////////// mysql_free_result($result); $query = "SELECT name, won FROM records WHERE (won > 0) ORDER BY won DESC"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<li><div class=\"topic\"> <div class=\"topic_txt\"><p><strong>Wins</strong></p></div> <div class=\"topic_stuff_hold\">"; echo "<div class=\"topic_stuff\"><table width=\"150\" border=\"0\"> <tr> <td width=\"1050\"><p>No Wins</p></td> <td width=\"150\"><p><strong>Yet</strong></p></td> </tr> </table></div>"; echo "</div></div></li>"; } else { echo "<li><div class=\"topic\"> <div class=\"topic_txt\"><p><strong>Wins</strong></p></div> <div class=\"topic_stuff_hold\">"; for ($i = 0; $i < 6; $i++, $row = mysql_fetch_assoc($result)) { $won_name = $row['name']; $won = $row['won']; echo "<div class=\"topic_stuff\"><table width=\"150\" border=\"0\"> <tr> <td width=\"1050\"><p>$won_name</p></td> <td width=\"150\"><p><strong>$won</strong></p></td> </tr> </table></div>"; } echo "</div></div></li>"; } ///////////////////////////////////// //LOSSES ///////////////////////////////////// mysql_free_result($result); $query = "SELECT name, lost FROM records WHERE (lost > 0) ORDER BY lost DESC"; $result = mysql_query($query); if(mysql_num_rows($result) == 0) { echo "<li><div class=\"topic\"> <div class=\"topic_txt\"><p><strong>Losses</strong></p></div> <div class=\"topic_stuff_hold\">"; echo "<div class=\"topic_stuff\"><table width=\"150\" border=\"0\"> <tr> <td width=\"1050\"><p>No Losses</p> </td> <td width=\"150\"><p><strong>Yet</strong></p> </td> </tr> </table></div>"; echo "</div></div></li>"; } else { echo "<li><div class=\"topic\"> <div class=\"topic_txt\"><p><strong>Losses</strong></p></div> <div class=\"topic_stuff_hold\">"; for ($i = 0; $i < 6 ; $i++, $row = mysql_fetch_assoc($result)) { $lost_name = $row['name']; $lost = $row['lost']; echo "<div class=\"topic_stuff\"><table width=\"150\" border=\"0\"> <tr> <td width=\"1050\"><p>$lost_name</p> </td> <td width=\"150\"><p><strong>$lost</strong></p> </td> </tr> </table></div>"; } echo "</div></div></li>"; } ?> THESE ARE THE ECHOED RESULTS- I asterisked the names. Wins Losses ***** ***** - this name shouldn't be here and returns no # 2697 ***** ***** 103 444 ***** ***** 37 186 ***** ***** 26 33 ***** ***** 17 24 ***** 14 Now this same code runs about 12 different stats and displays some of them properly and some with the extra name. On one the extra name has a number. If anybody has some insight it would be great as I have spent more time on this than what this simple problem deserves. Thanks in advance.

« previous php.notes (#168815) next »