Welcome Guest, Not a member yet? Register   Sign In
Unusual ActiveRecord Result
#2

[eluser]xwero[/eluser]
Try this
Code:
$this->db->select('t2.url, t2.title');
$this->db->from('exhibitions t1, galleries t2');
$this->db->where('t1.url',$this->uri->segment(3));
$this->db->where('t2.exhibitId = t1.exhibitionsId'); // silent join
$query = $this->db->get();
return $query->row();
It's a single sql statement with a silent join which outputs an object with the properties url and title.

If you are using the row method it outputs a one dimensional object so the foreach doesn't work. If you use it, it should be like this
Code:
$url = $this->uri->segment(3);

            $this->db->select('exhibitionsId');
            $this->db->from('exhibitions');
            $this->db->where('url',$url);
            $exhibitions_list = $this->db->get();
            $row = $exhibitions_list->row();

            $this->db->select('url, title');
                $this->db->from('galleries');
                $this->db->where('exhibitId', $row->exhibitionsId);
                $galleryExhibitions_data = $this->db->get();
                return $galleryExhibitions_data->result_array();


Messages In This Thread
Unusual ActiveRecord Result - by El Forum - 07-01-2008, 12:06 AM
Unusual ActiveRecord Result - by El Forum - 07-01-2008, 12:45 AM
Unusual ActiveRecord Result - by El Forum - 07-01-2008, 01:11 AM
Unusual ActiveRecord Result - by El Forum - 07-01-2008, 01:19 AM
Unusual ActiveRecord Result - by El Forum - 07-01-2008, 01:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB