Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的MySQL连接两表查询_Php_Mysql_Codeigniter - Fatal编程技术网

Php codeigniter中的MySQL连接两表查询

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

我有两张桌子,限额和交易

但只能得到销售订单…请帮助我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.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();