Welcome Guest, Not a member yet? Register   Sign In
Neater way to extract 'count(id)' style entries from query->row() call
#1

[eluser]jedd[/eluser]
I want to pull a count of a table, which is pretty straightforward, but the juggling of the return values just seems really quite messy. I expect there's a tidier CI way of doing this.

I have some code like this:
Code:
$query = $this->db->query ('SELECT COUNT(id)
                    FROM tablewotsit' );
$raw_count = (array)$query->row();
$actual_count  = $rawcount['COUNT(id)'];

I can't do the ['COUNT(id)'] bit to the $query-row directly. I tried not casting to array, and doing the -> thing to the 'COUNT(id)' string, but PHP choked with parenthesis in the attribute/key. If there were multiple responses I'd do the foreach $key=>$value thing and happily take $value, but that approach seems wrong given I know I'm dealing with just one row.


Messages In This Thread
Neater way to extract 'count(id)' style entries from query->row() call - by El Forum - 03-01-2009, 07:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB