MySQL JOIN LEFT查询空白

时间:2016-08-15 19:19:41

标签: php mysql mysqli left-join

我运行下面的查询来链接两个表,并根据id或magacin_sifra获取第二个表中的值。

$query = "SELECT 
    gumi.magacin_sifra, magacin_pp.magacin_kolicina as kolicina_pp, magacin_pp.magacin_cena as cena_pp
    FROM gumi
    LEFT JOIN magacin_pp ON gumi.magacin_sifra = magacin_pp.magacin_sifra       
     ";

$results = $conn->query($query);
if($results->num_rows) {
    while($row = $results->fetch_object()) {
        echo "{$row->magacin_ime} ({$row->kolicina_pp}) = {$row->cena_pp}<br>";
    }
}else {
    echo 'No results!';
}

然而,我得到的输出完全是空白的。

() = 
() = 
() = 
() = 
() = 
() = 
() = 

我做错了吗?

var_dump($results) = object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(3) ["lengths"]=> NULL ["num_rows"]=> int(7) ["type"]=> int(0) }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:-1)

你能为$ results尝试var_dump并在这里显示吗?

var_dump($results)