![]() |
[SOLVED] Output problems with COUNT - 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] Output problems with COUNT (/showthread.php?tid=18758) |
[SOLVED] Output problems with COUNT - El Forum - 05-17-2009 [eluser]Unknown[/eluser] I'm having some problems outputting a COUNT from SQL... My SQL query is as follows: Code: $this->db->select('entry_slug,entry_title,entry_body,entry_published,user_name,user_showname,COUNT(comment_id)'); My template looks like so: Code: <?= file_get_contents($_SERVER['DOCUMENT_ROOT'] .'header.html'); ?> Everything else outputs just fine, but I can't figure out how to print the COUNT result in my views template. Any ideas? Edit: Solved it with the slight addition 'AS comment_id' in the SQL, after COUNT(comment_id) [SOLVED] Output problems with COUNT - El Forum - 05-17-2009 [eluser]jedd[/eluser] Hi Selyoid and welcome to the CI forums. It might just be a naming problem - I don't use the AR class, but have issues with results from COUNTs because of the parenthesis. You can use the 2nd parameter of $this->db->SELECT() - when set to FALSE it doesn't try to do anything magical with your first parameter, so you can rename it using the SQL AS feature to something more useful - such as count_comment_id More information in the [url="http://ellislab.com/codeigniter/user-guide/database/active_record.html"] A R section of the user guide[/url], specifically in the Select paragraph. |