CodeIgniter Forums
Query translation in Active Record format - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Query translation in Active Record format (/thread-53281.html)



Query translation in Active Record format - El Forum - 07-17-2012

[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



Query translation in Active Record format - El Forum - 07-17-2012

[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.


Query translation in Active Record format - El Forum - 07-18-2012

[eluser]Aken[/eluser]
Try:

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



Query translation in Active Record format - El Forum - 07-18-2012

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