0

我正在尝试遍历给定列名的 MYSQL 表中的所有行。我正在查看 PHP 文档和 StackOverflow 问题,但由于某种原因,while循环方法并不完全有效。这是我到目前为止所拥有的:

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]);
}

此代码仅返回表中的第一个条目,如下所示

--------------------
placeholder    user //(same as $currentUser)
NULL           value1
NULL           value2
4

1 回答 1

3

该函数mysqli_fetch_array每次调用仅返回 1 行。您需要在函数返回值时进行迭代:

$result = mysqli_query($__CONNECTION__, $getIpQuery) 
while($row = mysqli_fetch_array($result)){
    for($x=0;$x<count($row);$x++)
    {
        printf("%s", $row[$x]);
    } 
}
于 2013-10-20T19:36:53.747 回答