Home  >  Article  >  Backend Development  >  php关于mysql_fetch_array的while计数的问题

php关于mysql_fetch_array的while计数的问题

WBOY
WBOYOriginal
2016-06-06 20:34:481159browse

我写的是从数据库中获取某个表的信息,信息有多行,我想转成json发送给客户端。
我并没有用到对象。

<code>$select2 = "select * from grouptable where groupid='$groupid'";
// echo $select2;
$result2 = mysql_db_query($database, $select2);
$i=0;
while($row2=mysql_fetch_array($result2)){
    //echo "i=$i";
    echo $row2[0]." ";
    echo $row2[1]." ";
    echo $row2[2]." ";
    echo $row2[3]." ";
    // $result[$i][$index[0]]=$row2[0];
    // $result[$i][$index[1]]=$row2[1];
    // $result[$i][$index[2]]=$row2[2];
    // $result[$i][$index[3]]=$row2[3];
    $i=$i+1;
    echo "i=$i";
    echo "";
}
</code>

我的数据库是有两条记录的,为什么这echo "i=$i";始终输出的都是1?我想的是1,2?这个while()循环应该执行两次吧?

回复内容:

我写的是从数据库中获取某个表的信息,信息有多行,我想转成json发送给客户端。
我并没有用到对象。

<code>$select2 = "select * from grouptable where groupid='$groupid'";
// echo $select2;
$result2 = mysql_db_query($database, $select2);
$i=0;
while($row2=mysql_fetch_array($result2)){
    //echo "i=$i";
    echo $row2[0]." ";
    echo $row2[1]." ";
    echo $row2[2]." ";
    echo $row2[3]." ";
    // $result[$i][$index[0]]=$row2[0];
    // $result[$i][$index[1]]=$row2[1];
    // $result[$i][$index[2]]=$row2[2];
    // $result[$i][$index[3]]=$row2[3];
    $i=$i+1;
    echo "i=$i";
    echo "";
}
</code>

我的数据库是有两条记录的,为什么这echo "i=$i";始终输出的都是1?我想的是1,2?这个while()循环应该执行两次吧?

只有一条数据符合 groupid 这个条件吧?

你确定里面有数据?

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