CodeIgniter Forums
[Solved] Count where - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Solved] Count where (/showthread.php?tid=18211)



[Solved] Count where - El Forum - 04-29-2009

[eluser]nebulom[/eluser]
Is there any way I can count where? Like
Code:
->count_where('SOME_TABLE', array('COLUMN', $value))
Or any other solution related to this problem? Thanks in advance.


[Solved] Count where - El Forum - 04-29-2009

[eluser]davidbehler[/eluser]
Code:
$this->db->where('COLUMN', $value);
$this->db->from('SOME_TABLE');
echo $this->db->count_all_results();



[Solved] Count where - El Forum - 04-29-2009

[eluser]nebulom[/eluser]
Ok, thanks. I thought there might be a one-liner solution. Again, thanks a lot.


[Solved] Count where - El Forum - 04-29-2009

[eluser]Jagar[/eluser]
If you are using PHP5 you can use the chaining method as follow:

Code:
$this->db->from('table_name')->where('column_name',value)->count_all_results();
this is only available in php5.

http://ellislab.com/codeigniter/user-guide/database/active_record.html


[Solved] Count where - El Forum - 04-29-2009

[eluser]nebulom[/eluser]
Yes, and I'm with PHP4 so can't use chain methods. Thanks.