duanlan6259 2013-10-20 19:27
浏览 44
已采纳

如何在PHP中循环列条目?

I'm trying to iterate through all the rows in a MYSQL table given the column name. I'm looking through the PHP docs and StackOverflow questions, but for some reason the while loop method didn't exactly work. Here's what I have so far:

include 'dbcon.php';

$dbcon = getConnection();
$currentUser= $_COOKIE['currentUser'];
$getIpQuery = mysqli_query($dbcon, "SELECT $currentUser FROM ipList");

$row = mysqli_fetch_array($getIpQuery, MYSQLI_NUM);
printf(count($row));
for($x=0;$x<count($row);$x++)
{
    printf("%s", $row[$x]);
}

This code returns only the first entry in the table which looks like this

--------------------
placeholder    user //(same as $currentUser)
NULL           value1
NULL           value2
  • 写回答

1条回答 默认 最新

  • doumengyin0491 2013-10-20 19:36
    关注

    the function mysqli_fetch_array returns only 1 row per call. you need to iterate while the function returns values:

    $result = mysqli_query($__CONNECTION__, $getIpQuery) 
    while($row = mysqli_fetch_array($result)){
        for($x=0;$x<count($row);$x++)
        {
            printf("%s", $row[$x]);
        } 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?