How do I traverse a table that has no contiguous fields updated?
A MySQL table with the following fields
Id,cs,
The ID is a primary key, but the value is not contiguous
1,3,7,8,9,10,..... This
I need to traverse the Update table, the code is written out, the following query does not know how to loop
PHP Code
Here I have reached the total number of rows for this table $sql = "SELECT count (*) from". $db _table; $exec = mysql_fetch_array ($con); $allgoods = $exec [0]; Total number of rows $sql = "Update". $db _table. "' Set cs = '". Rand ($summin, $summax). "' ";//UPDATE statement
If the ID is sequential.
I think the following statement is possible.
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 contiguous
How does this work?
------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. "
"; }