用PHP从数据库获取行 - 没有返回

时间:2014-02-25 21:52:14

标签: php sql database

所以这是我的PHP代码:

$result = mysqli_query($con, "SELECT * FROM WW_temp");
$numrows = mysqli_num_rows($result);

if ($numrows!=0){
    while ($row = mysqli_fetch_assoc($result) && $numOfPics >= 1){
        $ImageFilename = $row["image"];
        echo "$ImageFilename///";
    $numOfPics--;
    }
}

当numOfPics设置为3时,我得到的输出是/////////(9'/')。 数据库中的“图像”列中肯定有一些字段。代码有什么问题吗?

1 个答案:

答案 0 :(得分:2)

你的逻辑很狡猾。目前您的while条件被解释为:

$row = (mysqli_fetch_assoc($result) && $numOfPics >= 1)

$row == true,有行和$numOfPics >= 1

将其更改为:

while ( ($row = mysqli_fetch_assoc($result)) && $numOfPics >= 1 ){

它应该表现得很明智。