Php codeigniter中的MySQL连接两表查询
我有两张桌子,限额和交易 但只能得到销售订单…请帮助我thanx 获取买卖双方的数据 试试这个Php codeigniter中的MySQL连接两表查询,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有两张桌子,限额和交易 但只能得到销售订单…请帮助我thanx 获取买卖双方的数据 试试这个 $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.li
$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();
如果存在相同的列名,则需要为它们指定别名以区分它们:
$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();
你想要什么?在你的问题中详细说明
$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();