Welcome Guest, Not a member yet? Register   Sign In
codeigniter and mysql inner join creating problem
#1

[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
#2

[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
#3

[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
#4

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

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB