2015-10-06 31 views
1

我想一個SQL COUNT的結果存儲在一個變量,然後divise他們爲int,但是我正在呈現的錯誤:mysqli_result不能轉換在

Notice: Object of class mysqli_result could not be converted to int in ----

$countrows = 'SELECT count(*) AS NumRows FROM time_slots'; 
$countresult = $db->query($countrows); 

$something = $countresult/3 ; 
echo $something; 

我用echo在測試時顯示結果... 我該如何解決這個問題?

+0

您的回顯是否顯示任何內容? – Epodax

+1

錯誤是不言自明的,'$ db-> query()'返回一個'mysqli_result'對象:http://php.net/manual/en/class.mysqli-result.php – CD001

回答

2

你需要首先得到結果,並在數學後存儲在變量中。

countrows = 'SELECT count(*) AS NumRows FROM time_slots'; 
$countresult = $db->query($countrows); 
$count = $countresult->fetch_assoc();    
$something = $count['NumRows']/3 ; 
echo $something; 
+0

@Krono我編輯了回答 – rray

相關問題