CodeIgniter Forums
codeigniter and mysql inner join creating problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: codeigniter and mysql inner join creating problem (/showthread.php?tid=43792)



codeigniter and mysql inner join creating problem - El Forum - 07-23-2011

[eluser]foysal[/eluser]
my model
Code:
function get_customer()
    {
      
        $this->db->select('*');
        $this->db->from('tbl_customer');
        $this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id');
        $query = $this->db->get();
        return $query->result();
    }

my controller

Code:
function index()
    {
      $this->load->model('sh_model');
      $variable['customer'] = $this->sh_model->get_customer();
      $this->load->view('sh_view', $variable);
    }


my view

Code:
foreach($customer as $item)
    {
       echo $item->customer_id;
       echo $item->customer_first_name;
    }



I am getting no result. Even no error coming.

If you have good tutorial on mysql inner join and codeigniter, please share with me.


foysal


codeigniter and mysql inner join creating problem - El Forum - 07-23-2011

[eluser]InsiteFX[/eluser]
Third parameter is the join type!
Code:
$this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id', 'inner');

InsiteFX


codeigniter and mysql inner join creating problem - El Forum - 07-23-2011

[eluser]foysal[/eluser]
Dear Insite FX

I tried your code. But I am getting only first table data.


Even I tried below codes in my model

Code:
$this->db->select('tbl_customer.*,tbl_sales.*');
$this->db->from('tbl_customer');
$this->db->join('tbl_sales', 'tbl_sales.customer_id = tbl_customer.customer_id','inner');

but i did not get data from both tables.

If you have any good tutorial on mysql inner join and codeigniter you can share it with me.


foysal


codeigniter and mysql inner join creating problem - El Forum - 07-23-2011

[eluser]InsiteFX[/eluser]
Code:
return $query->result_array();

InsiteFX