2015-12-01 60 views
1

我嘗試從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

哪一個是第18行?我只能猜測它是'if($ result-> num_rows> 0){'或'$ result = $ link-> query($ sql);',無論如何,請向我們展示大圖(前代碼) – MorKadosh

+0

是的..它的if($ result-> num_rows> 0) –

+0

我不能讓你的完整代碼,因爲它不會讓我發佈,因爲我的帖子有太多code.the上部分只需要數據庫連接和會話 –

回答

0

您的查詢很可能會返回數據庫錯誤。 num_rows正在嘗試評估一個空對象。讓腳本死於錯誤並返回消息。一旦你找出你出錯的地方,這會指引你正確的方向。

if ($result === false) { die(mysql_error($link)); } 

更新:讀取您的評論後,似乎列pckge_info.pckgeID可能不存在。請仔細檢查以確保您正在爲正在查詢的表調用正確的列名稱。

0
Trying to get property of non-object 

這當您的對象爲空時發生,因此我會查看該查詢並查看是否$ result對象已填充,最可能是$ resultnull當您運行查詢,從而出現錯誤。