>  기사  >  백엔드 개발  >  怎么遍历更新没有连续字段的表

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

WBOY
WBOY원래의
2016-06-13 13:15:27818검색

如何遍历更新没有连续字段的表?
一个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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.