note 97641 added to control-structures.for

From: Date: Fri, 30 Apr 2010 04:28:32 +0000
Subject: note 97641 added to control-structures.for
Groups: php.notes 
Request: Send a blank email to php-notes+get-168799@lists.php.net to get a copy of this message
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. ---- Server IP: 192.41.40.227 Probable Submitter: 65.11.20.201 ---- Manual Page -- http://www.php.net/manual/en/control-structures.for.php Edit -- https://master.php.net/note/edit/97641 Del: integrated -- https://master.php.net/note/delete/97641/integrated Del: useless -- https://master.php.net/note/delete/97641/useless Del: bad code -- https://master.php.net/note/delete/97641/bad+code Del: spam -- https://master.php.net/note/delete/97641/spam Del: non-english -- https://master.php.net/note/delete/97641/non-english Del: in docs -- https://master.php.net/note/delete/97641/in+docs Del: other reasons-- https://master.php.net/note/delete/97641 Reject -- https://master.php.net/note/reject/97641 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168799) next »