CodeIgniter Forums

Full Version: Query translation in Active Record format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Alhazred[/eluser]
How to write this query in Active Record format?
Code:
SELECT c.id AS id,c.name AS name,t.name AS category
FROM category c, type t
WHERE t.id = c.category
ORDER BY c.name

El Forum

[eluser]Alhazred[/eluser]
Here what I've tried
Code:
$this->db->select('c.id AS id, c.name AS name, t.name AS category');
$this->db->from('category c, tipo_category t');
$this->db->where('t.id','c.category');

$result = $this->db->get();
I don't have any error, but that generates an empty result, while the SQL version finds 3 records.

El Forum

[eluser]Aken[/eluser]
Try:

Code:
$this->db->where('t.id = c.category');

El Forum

[eluser]Alhazred[/eluser]
Thenks, it works.