How do I echo echo in array

1
   public static function getAllCount(){
    $sql = "SELECT COUNT(Title) from ".self::$tablename." GROUP BY category_id";
    $query = Executor::doit($sql);
    return Model::many($query[0],new EventData());
}
 FOREACH ---

 foreach ($evcount as $c) {      
 }

 print_r($evcount);

?>  

RETORNO -----

  Array
  (
    [0] => EventData Object
    (
        [name] => 
        [lastname] => 
        [email] => 
        [category_id] => NULL
        [password] => 
        [created_at] => NOW()
        [COUNT(Title)] => 4
    )

[1] => EventData Object
    (
        [name] => 
        [lastname] => 
        [email] => 
        [category_id] => NULL
        [password] => 
        [created_at] => NOW()
        [COUNT(Title)] => 62
    )

I want to echo echo by pulling COUNT(title)=>

But when I give the echo it gives this error

  

Call to undefined method EventData :: COUNT ()

    
asked by anonymous 01.11.2016 / 17:54

1 answer

3

The query returns an object with the columns of the database that viewed properties so treat them properly :COUNT() is not a method.

"SELECT COUNT(Title) from ".self::$tablename." GROUP BY category_id"

To solve this, give an alias to the column and then access it normally as a prority.

"SELECT COUNT(Title) as total from ".self::$tablename." GROUP BY category_id"

Inside the foreach do:

echo $c->total;

If the object has no methods, it is simpler to return a stdclass.

    
01.11.2016 / 18:02