1

i want to store the results of an SQL COUNT in a variable, then divise them, however i'm presented with the error:

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;

I used echo to display the result while testing... How do i fix this?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Krono
  • 1,352
  • 1
  • 14
  • 33

1 Answers1

3

You need get first the result and store in a variable after do the math.

countrows = 'SELECT count(*) AS NumRows FROM time_slots';
$countresult = $db->query($countrows);
$count = $countresult->fetch_assoc();               
$something = $count['NumRows']/3 ;
echo $something;
rray
  • 2,518
  • 1
  • 28
  • 38