rubing Posted August 21, 2008 Share Posted August 21, 2008 I am trying to code a script that stops running when there are no results found in my table. When i run this it says that the result set is 0, but it keeps executing. $count =1; while ($count=1) { $api=mt_rand(10000000,99999999); $query="SELECT * FROM api WHERE api=".$api.""; if ($results=$conn->query($query)) { $row_cnt = $results->num_rows; printf("Result set has %d rows.\n", $row_cnt); if($row_cnt==0) { $count=0; } $results->close(); } Link to comment https://forums.phpfreaks.com/topic/120641-solved-while-loop-not-stopping/ Share on other sites More sharing options...
Psycho Posted August 21, 2008 Share Posted August 21, 2008 This is attempting to ASSIGN a value of 1 to the variable $count and, if successful, returns true. while ($count=1) This does a COMPARISON of $count to see if it is equal to 1, and returns true if it is. while ($count==1) Link to comment https://forums.phpfreaks.com/topic/120641-solved-while-loop-not-stopping/#findComment-621625 Share on other sites More sharing options...
rubing Posted August 22, 2008 Author Share Posted August 22, 2008 Gee, that was dumb of me. Thanks for spottin that one! Link to comment https://forums.phpfreaks.com/topic/120641-solved-while-loop-not-stopping/#findComment-622647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.