2017-05-06 42 views
0

的財產我不斷收到錯誤PHP錯誤信息 - 試圖讓非對象

想在我的PHP代碼來獲得非對象

的財產。以下是發生錯誤的代碼片段。

這是錯誤日誌指的是線路:$high = $highrow->price;

$mysqli = new mysqli($server, $user, $pass, $db); 
$highresult = $mysqli->query("SELECT * FROM $code WHERE date=$date AND time=$hour ORDER BY price desc LIMIT 1"); 
$highrow = $highresult->fetch_object(); 
$high = $highrow->price; 
echo $high." - High<br>"; 
$hightime = $highrow->time; 
echo $hightime."<br>"; 

我缺少的東西?

+2

SELECT * FROM $ code where $ code? –

+0

它是一個函數的一部分。它只是導致問題的片段不是整個事情。 – lrave1

回答

1
$mysqli = new mysqli($server, $user, $pass, $db); 
$highresult = $mysqli->query("SELECT * FROM $code WHERE date='$date' AND time='$hour' ORDER BY price desc LIMIT 1"); 
$highrow = $highresult->fetch_object(); 
$high = $highrow->price; 
echo $high." - High<br>"; 
$hightime = $highrow->time; 
echo $hightime."<br>"; 

編輯您的選擇查詢如上

SQL大約需要文本值單引號(大多數數據庫系統 也將允許雙引號)。

+0

是的,這將工作。 –

0

的問題是與這一行:

$high = $highrow->price; 

$high這裏是具有對象的陣列,其中具有一個以上的數組。 所以不是這一行試試:

$high = $highrow[0]->price; 

或使用

foreach($highrow as $data) 
{ 
    echo $data->price; 
}