Welcome Guest, Not a member yet? Register   Sign In
Active records and complex join query
#2

[eluser]seanloving[/eluser]
[quote author="softsaurus" date="1274377216"]
What I'd like my query to do is be able to get the fields contained in 'images' and link them to the entry on my 'blog' by using the relational table.
[/quote]

I'm learning too, so you should ask for another opinion, but I think you might try something like this:
Code:
$this->db->select('entries.id, entries.title, entries.body, images.title AS image_title, images.description, images.src');
$this->db->from('entries');
$this->db->where('entries.id' = $entry_id); // the calling function supplies $entry_id
$this->db->join('images_entries', 'entries.id = images_entries.entry_id', 'left');
$this->db->join('images', 'images_entries.image_id = images.id', 'left');
$q = $this->db->get();

good luck
--Sean Loving


Messages In This Thread
Active records and complex join query - by El Forum - 05-20-2010, 06:40 AM
Active records and complex join query - by El Forum - 05-20-2010, 08:35 AM
Active records and complex join query - by El Forum - 05-20-2010, 09:57 AM
Active records and complex join query - by El Forum - 05-20-2010, 11:33 AM
Active records and complex join query - by El Forum - 06-09-2010, 02:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB