Welcome Guest, Not a member yet? Register   Sign In
selet data from multiple tables
#1

[eluser]Paleleaves[/eluser]
Hi,

I want to get data from two tables. I just want to know how to write a query for this. Please see the attachment for a graphical view.


thanks in advance..

cheers!!!
#2

[eluser]Brad K Morse[/eluser]
Try this

Code:
$this->db->select('page_level_one.levelone_id,
                   page_level_two.levelone_id,
                   page_level_two.levelone_id as sublevel');
$this->db->from('page_level_one');
$this->db->join('page_level_two', 'page_level_one.levelone_id = page_level_two.levelone_id');
$this->db->where('page_level_one.levelone_id', $this->uri->segment(3));
$q = $this->db->get();

notice segment(3), that is based upon your URL structure being /segment1/segment2/id

segment 3 being the ID of the levelone_name, that you want to display all of its sublevels.

So the AS sublevel will contain the appropriate ID's of all the sublevels, then pass this into another function to print out the leveltwo_name

This is untested, so the query may not work.
#3

[eluser]Paleleaves[/eluser]
Hi,

Thanks for the reply. I don't want to pass any uri segment to get the result as i shown in the attachment. This is actually a menu with sublevels should be loaded with the site. So nothing passed initially when site loading. Can you give me a solutions like that..

Thanks again!!
#4

[eluser]techgnome[/eluser]
It would be the same, only with out the call to the Where method...

-tg
#5

[eluser]Paleleaves[/eluser]
Hi,

I tried that method but it shows error like "A PHP error was encountered.

Here is the code I tried

Code:
$this->db->select('page_level_one.levelone_id,
                   page_level_two.levelone_id,
                   page_level_two.levelone_id as sublevel');
$this->db->from('page_level_one');
$this->db->join('page_level_two', 'page_level_one.levelone_id = page_level_two.levelone_id');
        //$this->db->where('page_level_one.levelone_id', $this->uri->segment(3));
        $SqlInfo['item'] = $this->db->get();

Any suggestions for this would be really helpful.. Thanks..




Theme © iAndrew 2016 - Forum software by © MyBB