Home  >  Article  >  Backend Development  >  怎么遍历更新没有连续字段的表

怎么遍历更新没有连续字段的表

WBOY
WBOYOriginal
2016-06-13 10:46:30667browse

如何遍历更新没有连续字段的表?
一个mysql表, 有下列字段
id,cs,

id虽为主键,但值并不连续
1,3,7,8,9,10,.....这种

我需要遍历update这个表,代码写出来了,下面的query不知道该怎么循环了

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->这里我已得出这个表的总行数$sql      = "select count(*) from".$db_table;                    $exec      = mysql_fetch_array($con);                    $allgoods = $exec[0]; //总行数                                        $sql = "update `".$db_table."' set cs = '".rand($summin,$summax)."' ";//更新语句

如果id为连续的话.
我想下面的语句是可以的
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->for ($i=0;$i

可是,这里id并不连续

这该如何操作呢?

------解决方案--------------------
PHP code
$sql = "select id from ".$db_table;            $result = mysql_query($sql,$con);        while($row=mysql_fetch_object($result)){                       $id=$row->id;                    echo $id."<br>";                    }<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn