Vermillion Posted August 31, 2008 Share Posted August 31, 2008 <?php mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbactual); $query = "SELECT * FROM logs WHERE level = 8"; $result = mysql_query($query); $number = mysql_num_rows($result); $i = 0; echo "<table><tr>"; echo "<td><strong>Log ID</strong></td><td><strong>User</strong></td><td><strong>User Level</strong></td><td><strong>Date</strong></td><td><strong>Time</strong></td><td><strong>Action</strong></td></tr>"; while ($i < $number) { $id = mysql_result($result,$i,"id"); $user_id = mysql_result($result,$i,"user_id"); $level = mysql_result($result,$i,"level"); $date = mysql_result($result,$i,"date"); $time = mysql_result($result,$i,"time"); $action = mysql_result($result,$i,"action"); echo "<tr><td>$id</td><td>$user_id</td><td>$level</td><td>$date</td><td>$time</td><td>$action</td></tr>"; } echo "</table>"; ?> For some reason, that causes an infinite loop. The resource ID is #12, and $number is 3. I have $i set to 0, yet for some reason this is an infinite loop. Can someone help me find the problem? Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/ Share on other sites More sharing options...
.josh Posted August 31, 2008 Share Posted August 31, 2008 you never increment $i Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630064 Share on other sites More sharing options...
phpcodec Posted August 31, 2008 Share Posted August 31, 2008 you have forgot to put $i++; so it increments the $i variable correct code: <?php mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbactual); $query = "SELECT * FROM logs WHERE level = 8"; $result = mysql_query($query); $number = mysql_num_rows($result); $i = 0; echo "<table><tr>"; echo "<td><strong>Log ID</strong></td><td><strong>User</strong></td><td><strong>User Level</strong></td><td><strong>Date</strong></td><td><strong>Time</strong></td><td><strong>Action</strong></td></tr>"; while ($i < $number) { $id = mysql_result($result,$i,"id"); $user_id = mysql_result($result,$i,"user_id"); $level = mysql_result($result,$i,"level"); $date = mysql_result($result,$i,"date"); $time = mysql_result($result,$i,"time"); $action = mysql_result($result,$i,"action"); echo "<tr><td>$id</td><td>$user_id</td><td>$level</td><td>$date</td><td>$time</td><td>$action</td></tr>"; $i++; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630066 Share on other sites More sharing options...
Vermillion Posted August 31, 2008 Author Share Posted August 31, 2008 This is the second stupidiest mistake I have done so far on my site :/. Thanks a lot guys, much appreciated. Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630068 Share on other sites More sharing options...
.josh Posted August 31, 2008 Share Posted August 31, 2008 also just fyi you should look into mysql_fetch_assoc instead of using a combo of _num_rows and mysql_result. It's cleaner and much more efficient. <?php mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbactual); $query = "SELECT * FROM logs WHERE level = 8"; $result = mysql_query($query); echo "<table><tr>"; echo "<td><strong>Log ID</strong></td><td><strong>User</strong></td><td><strong>User Level</strong></td><td><strong>Date</strong></td><td><strong>Time</strong></td><td><strong>Action</strong></td></tr>"; while ($r = mysql_fetch_assoc($result)) { extract($r); echo "<tr><td>$id</td><td>$user_id</td><td>$level</td><td>$date</td><td>$time</td><td>$action</td></tr>"; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630069 Share on other sites More sharing options...
DarkWater Posted August 31, 2008 Share Posted August 31, 2008 You know, that mysql_result is much slower than mysql_fetch_assoc, correct, Vermillion? EDIT: CV beat me to it. D: Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630070 Share on other sites More sharing options...
Vermillion Posted August 31, 2008 Author Share Posted August 31, 2008 Ah okay, will consider it too. Thanks for the tip! Link to comment https://forums.phpfreaks.com/topic/122053-solved-mysterious-infinite-loop/#findComment-630080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.