CodeIgniter Forums
Active record count() possible? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active record count() possible? (/showthread.php?tid=23890)



Active record count() possible? - El Forum - 10-25-2009

[eluser]stef25[/eluser]
Is it possible to do something like this with CI Active Record?

$this->db->select('tag_name', count('tag_name'));

It seems the count() part is just ignored and the query only returns tag_name. From what I've found on the forums and in the documentation this is not possible?

Anyone have a workaround?


Active record count() possible? - El Forum - 10-25-2009

[eluser]davidbehler[/eluser]
Code:
$this->db->select('tag_name');
$this->db->select("COUNT('tag_name') as my_count_var", FALSE);



Active record count() possible? - El Forum - 10-25-2009

[eluser]stef25[/eluser]
Excellent!

As you could probably guess, this is to build a tag cloud. I found a few solutions on the forum and the rest of the web but your solution worked very well out of the box. One small issue isn't clear, I posted in the relevant thread.