How to traverse a table that has no contiguous fields updated

Source: Internet
Author: User
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. "
"; }
  • Related Article

    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.