How can I Traverse tables without consecutive fields updated? A mysql table has the following field IDs. cs and id are the primary key, but the values are not consecutive ,..... in this case, I need to traverse the update table and write the code. the following query does not know how to loop through PHPcode. here I have obtained the total number of rows for this table $ SQL & quot; selectcount (*) from & quot ;. $ db _ how to traverse tables with no consecutive fields updated?
A mysql table with the following fields
Id, cs,
The id is a primary key, but the value is not consecutive.
1, 3, 7, 8, 9, 10 ,...
I need to traverse the update table and write the code. the following query does not know how to loop.
PHP code
Here I have obtained the total number of rows in this table $ SQL = "select count (*) from ". $ db_table; $ exec = mysql_fetch_array ($ con); $ allgoods = $ exec [0]; // The total number of rows $ SQL = "update "'. $ db_table. "'set cs = '". rand ($ summin, $ summax ). "'"; // update statement
If the id is continuous.
I think the following statements are acceptable.
PHP code
for ($i=0;$i<=$allgoods;$i++){$sql = "update "`.$db_table."' set cs= '".rand($summin,$summax)."' where id = '".$i."'";query....}
However, the id here is not consecutive
What should I do?
------ Solution --------------------
PHP code
$sql = "select id from ".$db_table; $result = mysql_query($sql,$con); while($row=mysql_fetch_object($result)){ $id=$row->id; echo $id."
"; }