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

[eluser]jedd[/eluser]
[quote author="JayTee" date="1235937401"]
Code:
$raw_count = $this->db->query("select count(*) as ct from yourtable")->row(0)->ct;
[/quote]

Ah, excellent, thanks. I've used 'AS' before, but only when trying to neaten out joins from tables with identical named columns. Didn't even think of it here.

Quote:Be aware that Method Chaining only works with PHP 5.

Which brings up that ol' hoary chestnut of how committed to writing PHP4-compatible code is the average CI user? I'm in two minds - the PHP4 side is encouraged by the fact that (pretty much) all CI example code uses PHP4-isms - and the PHP5 side by the fact that pretty much all my other reference material is based on PHP5.

For my own future readability I think I'll go halfway between my three lines and JayTee's one line, in this particular instance.


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



Theme © iAndrew 2016 - Forum software by © MyBB