Jump to content

[SOLVED] how to let a loop continue until all the rows in a table gets marked "DONE"


jjk2

Recommended Posts

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.

Link to comment
Share on other sites

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);
?>



 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.