codeignitercodeigniter-2codeigniter-datamapper

Printing Column count(*) in codeigniter


I am fetching data from a database like this.

select categories.categorie_name, count(*)
from names
join categories on names.categories_id=categories.categories_id
group by categories.categorie_name
order by 2

i got as a result 2 columns

 categorie_name  |  count(*) 

how ever when I try to acces the count(*) column from my view I can not print what is in the column.

<?php foreach ($categories as $categorie)
        echo $categorie->categorie_name." ".$categorie->count(*)."<br>";
?>

can you please advice how to solve this?


Solution

  • Try this

    select categories.categorie_name, count(*) as cnt
    from names
    join categories on names.categories_id=categories.categories_id
    group by categories.categorie_name
    order by 2
    

    then use cnt like $categorie->cnt;