jjk2 Posted April 18, 2009 Share Posted April 18, 2009 i am really stumped how to tackle this basically i need a loop that will keep going until all the rows in the table gets marked DONE. the tricky part is that, inside each loop, there is a function that adds more rows to the DB. Eventually the function is set to record no more rows. after several loops, all the rows in the database are marked DONE, and the loop stops. Quote Link to comment https://forums.phpfreaks.com/topic/154610-solved-how-to-let-a-loop-continue-until-all-the-rows-in-a-table-gets-marked-done/ Share on other sites More sharing options...
Mchl Posted April 18, 2009 Share Posted April 18, 2009 In each pass of the loop select the number of rows that are not marked "DONE". Continue the loop as long as this number is higher than 0. Quote Link to comment https://forums.phpfreaks.com/topic/154610-solved-how-to-let-a-loop-continue-until-all-the-rows-in-a-table-gets-marked-done/#findComment-813014 Share on other sites More sharing options...
jjk2 Posted April 19, 2009 Author Share Posted April 19, 2009 okay i've tried below....but it just seems to repeat forever, regardless of the $count. <?php $con = mysql_connect(""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("seok", $con); $result = mysql_query("SELECT * FROM `asdf` WHERE finished=0"); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $s = 0; while ($count != 0){ mysql_query("UPDATE asdf SET finished=1 WHERE finished=0"); if ($s == 12){ break; }else{ mysql_query("INSERT INTO asdf (id, finished, depth, link) VALUES ('', '0', $s, 'asdf.com')"); } //$count = mysql_num_rows($result); echo $count; $s++; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/154610-solved-how-to-let-a-loop-continue-until-all-the-rows-in-a-table-gets-marked-done/#findComment-813476 Share on other sites More sharing options...
Mchl Posted April 19, 2009 Share Posted April 19, 2009 You have no query counting rows that are not marked "DONE". Quote Link to comment https://forums.phpfreaks.com/topic/154610-solved-how-to-let-a-loop-continue-until-all-the-rows-in-a-table-gets-marked-done/#findComment-813706 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.