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.

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



 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.