How to traverse tables with no consecutive fields Updated

Source: Internet
Author: User
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. how can I traverse the update table without consecutive fields?
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."
"; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.