I have two table, limit and transaction
$wherehis= array('status'=>'Yes','company_id' =>$compnayid);
$this->db->select('type,tra.amount,tra.qty,limit_id');
$this->db->where($wherehis);
$this->db->limit(100);
$this->db->order_by('tra.tra_id','DESC');
$this->db->join('limit_history as sell', 'tra.sell_limit_id = sell.limit_id','left');
$this->db->join('limit_history as buy', 'tra.buy_limit_id = buy.limit_id','left');
$data['Histroy']= $this->db->get("tbltrancation as tra")->result_array();
but get only sell order....please help me thanx
get the buy and sell both data
Try this,
$this->db->limit(100);
$this->db->order_by('tra.tra_id','DESC');
$this->db->join('limit_history as sell', '(tra.sell_limit_id = sell.limit_id AND tra.buy_limit_id = buy.limit_id)','left');
$data['Histroy']= $this->db->get("tbltrancation as tra")->result_array();
When there are identical column names you need to give them an alias to differentiate them:
$this->db
->select('tra.*, sell.amount as sell_amount, sell.qty as sell_qty, buy.amount as buy_amount, buy.qty as buy_qty')
->from('tbltrancation as tra')
->join('limit_history as sell', 'tra.sell_limit_id = sell.limit_id', 'left')
->join('limit_history as buy', 'tra.buy_limit_id = buy.limit_id', 'left')
->order_by('tra.tra_id', 'desc')
->limit(100);
$data['Histroy'] = $this->db->get()->result_array();