即使数据库中的数据,PHP mysqli_num_rows也始终返回0

时间:2017-08-11 21:04:32

标签: php mysql mysqli

我有几个数据库表。所有这些都充满了数据。我有以下PHP代码尝试检索数据:

$sql = "select inspection_date, inspection_type, capacity, criticality, man_hours from $table_name where device_number = '$device_number' order by inspection_date";

//printf("sql = $sql <br/>");

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        $final_array[] = array("device_number"=>$all_ld_formatted[$i]['device_number'], "old_device_number"=>$all_ld_formatted[$i]['old_device_number'], 
            "type"=>$all_ld_formatted[$i]['type'], "building"=>$all_ld_formatted[$i]['building'], "room"=>$all_ld_formatted[$i]['room'], 
            "power"=>$all_ld_formatted[$i]['power'], "inspection_date"=>$row['inspection_date'], "inspection_type"=>$row['inspection_type'], 
            "capacity"=>$row['capacity'], "criticality"=>$row['criticality'], "man_hours"=>$row['man_hours']);
    }
} else {
    printf("no results <p/>");
}

上面的代码在for循环中运行。那就是为什么你在那里看到$ all_ld_formatted [$ i] [&#39; value&#39;]的东西。出于某种原因,代码总是返回&#34;没有结果&#34;。但是,如果我取消注释printf(&#34; sql = $ sql&#34;);行,并将查询复制并粘贴到PHPMyAdmin中,我总能得到我正在寻找的结果。请帮助,谢谢!

此致

Chris Martino

0 个答案:

没有答案