douwuying4709 2016-07-21 07:08
浏览 45

MySQL在codeigniter中加入两个表查询

I have two table, limit and transaction enter image description here enter image description here

        $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

enter image description here

  • 写回答

2条回答 默认 最新

  • doubu1964 2016-07-21 07:18
    关注

    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();
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向