2015-10-06 66 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

相关问题