Welcome Guest, Not a member yet? Register   Sign In
Active Record bug in 2.0
#1

[eluser]phybertek[/eluser]
Hello,

I spent 2 hours trying to run a query with Active Records. Is this a bug?

Code:
$q = $this->db->select('CITY','count(id) as cntr')
     ->from(tCITY)
     ->group_by('CITY')
     ->get();

return $q;
--
//$query = the output of your model code returned $q.

foreach ($query->result() as $row)
{
    echo "$row->id | $row->cntr<br>";
}


This produced error. I don't have the error on me as I am at work, but if you run
this same query directly, it works fine. You can't access the second table column.
#2

[eluser]Armchair Samurai[/eluser]
select() takes two parameters, a string and an optional boolean, so your code is incorrect. Try this:

Code:
$q = $this->db->select('CITY')
     ->select('count(id) cntr', FALSE)
     ->from(tCITY)
     ->group_by('CITY')
     ->get();

Also, it looks like you're missing the quotes around tCITY.
#3

[eluser]phybertek[/eluser]
Merci beaucoup!

Yeah, I tried to regenerate what I was trying last night. This was not my exact query, but I think problem is putting multiple columns in the first select. Thank you for clear this up for me.

Thank you again.

-Marquis
#4

[eluser]danmontgomery[/eluser]
You can put multiple columns in, but they have to be in the first parameter.

Code:
$this->db->select('CITY, count(id) as cntr', FALSE)




Theme © iAndrew 2016 - Forum software by © MyBB