我试图从2个单独的表中查看数据,但出现了这个错误:
"Notice: Trying to get property of non-object in D:\xampp\htdocs\testsubject\User\inventory.php on line 18"
这是我的PHP代码:
$sql = "SELECT storage_details.itemCODE,storage_details.pckgeID,storage_details.cndition,storage_details.duration,pckge_info.price,storage_details.status
FROM storage_details
INNER JOIN pckge_info
ON storage_details.pckgeID=pckge_info.pckgeID";
$result = $link->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "itemcode: " . $row["itemCODE"]. " - packageid: " . $row["pckgeID"]. "condition: " . $row["cndition"]. "duration: " . $row["duration"]. " status: " . $row["price"]. " " . $row["status"]."<br>";
}
} else {
echo "0 results";
}
mysql_free_result($result);
答案 0 :(得分:0)
Trying to get property of non-object
当您的对象为null时会发生这种情况,因此我会查看查询并查看是否填充了 $ result 对象,很可能 $ result null < / strong>当您运行查询并因此运行错误时。
答案 1 :(得分:0)
您的查询很可能会返回数据库错误。 num_rows正在尝试计算一个null对象。让您的脚本出错并返回消息。一旦你找出出错的地方,这将指向正确的方向。
if ($result === false) { die(mysql_error($link)); }
更新:阅读完评论后,似乎pckge_info.pckgeID列可能不存在。仔细检查以确保为要查询的表调用正确的列名。