doutuo1908 2018-08-11 09:28
浏览 84
已采纳

使用Codeigniter进行复杂查询连接

I have a query which produce results in phpmyadmin but not in codeigniter.

$sql = "SELECT express_interests.*, 
       cl_to  .User_Name AS ToClient, 
       cl_from.User_Name AS FromClient,
       cl_from.Member_Id AS FromMid,
       cl_to.Member_Id AS ToMid

FROM express_interests  
    INNER JOIN users AS cl_to ON cl_to.User_Id = express_interests.To_Id
    INNER JOIN users AS cl_from ON cl_from.User_Id = express_interests.User_Id";

i want to use the same query in codeignitor. This is what i have used

$this->db->select('express_interests.*, 
       cl_to  .User_Name AS ToClient, 
       cl_from.User_Name AS FromClient,
       cl_from.Member_Id AS FromMid,
       cl_to.Member_Id AS ToMid
');

$this->db->from('express_interests');


$this->db->join('users AS cl_to', 'cl_to.User_Id = express_interests.To_Id');
$this->db->join('users AS cl_from', 'cl_from.User_Id = express_interests.User_Id');

when i use this it says

Unknown column 'cl_to .User_Name' in 'field list'

what is the proper way to use the above query in codeigniter.

  • 写回答

2条回答 默认 最新

  • doutao6380 2018-08-11 09:36
    关注
    $this->db->select('express_interests.*, 
           cl_to  .User_Name AS ToClient, 
           cl_from.User_Name AS FromClient,
           cl_from.Member_Id AS FromMid,
           cl_to.Member_Id AS ToMid
    ');
    

    Replace this with

    $this->db->select('express_interests.*, 
           cl_to.User_Name AS ToClient, 
           cl_from.User_Name AS FromClient,
           cl_from.Member_Id AS FromMid,
           cl_to.Member_Id AS ToMid
    ');
    

    Unwanted spacing in between table alias & column name

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图