1

This is from a wordpress query to see how many values in a custom table. Im hoping this will be the first step to doing simple pagination inside an admin page.

The array is stored inside $total

This is the output of print_r($total);

Array ( [0] => sCltdass Object ( [COUNT(*)] => 276 ) )

How do I store the number of rows in a variable so that I can do this: echo $countrows;

and it will output 276?

I keep trying variations of the following line:

 $count = $total[0]->COUNT();
 echo $count;

But nothing seems to work.

jojojohn
  • 725
  • 2
  • 10
  • 19
  • It can be done by quoting and enclosing in `{}` as `$total[0]->{'COUNT()'}` but you should really consider changing the original query to use an alias `SELECT COUNT() AS total` so it returns as `$total[0]->total` – Michael Berkowski May 29 '14 at 18:06
  • (I'm looking for the correct PHP docs to link you to) – Michael Berkowski May 29 '14 at 18:08
  • http://www.php.net/manual/en/language.variables.variable.php I guess it's part of the variable variables documentation, though the examples here mostly use vars inside rather than static strings... – Michael Berkowski May 29 '14 at 18:10

0 Answers0