2
這裏是我的代碼:SQL + PHP - 致命錯誤:無法使用類型mysqli_result作爲陣列的對象爲什麼
<?php
$con = mysqli_connect("127.0.0.1:3306","root","root","photoshare");
$query = "SELECT ID,nickname,photoLikes FROM tbl_photo";
$result = mysqli_query($con,$query);
$query_dislike = "SELECT nickname, idGivenLike FROM tbl_check_like";
$resultDislike = mysqli_query($con,$query_dislike);
$photoIDdislike;
$photoID;
while($photoID = mysqli_fetch_assoc ($result) || $photoIDdislike = mysqli_fetch_assoc($resultDislike) )
{
//checks if both of results
if($result["ID"] != $resultDislike["idGivenLike"])
{
echo "true";
}
}
?>
當我運行它,它說,下一行
if($result["ID"] != $resultDislike["idGivenLike"])
用H致命錯誤:Fatal error: Cannot use object of type mysqli_result as array
爲什麼它不工作,我該如何解決它?
在'if'塊 – NoLifeKing
'$結果[ 「ID」]替換'和'$ photoIDdislike' $ resultDislike''應該是'$ PHOTOID [ 「ID」] '和'$ resultDislik [「idGivenLike」]'應該是'$ photoIDdislike [「idGivenLike」]'在你的循環中。 –