如何在我的Codeigniter模型中使用SQL LEFT JOIN

时间:2017-03-01 08:22:39

标签: mysql codeigniter join

我在Codeigniter模型中使用LEFT JOIN进行查询。当我添加LEFT JOIN时,我的网页无法正常工作,并且如下所示

  

localhost页面无效

     

localhost目前无法处理此请求。 HTTP ERROR 500

这是我的查询。我添加了LEFT JOIN(非工作阶段)。我错了什么?请指导我。我是菜鸟。

$sql = "
        SELECT eu.user_id as user_id, DATE_FORMAT(eu.interview_plan_date, '%Y-%m-%d') as plan_date, DATE_FORMAT(eu.interview_plan_date, '%H:%i:%s') as start_time, DATE_FORMAT(DATE_ADD(eu.interview_plan_date, INTERVAL 1 HOUR), '%H:%i:%s') as end_time, count(1) AS cnt  
        FROM `entry_user_tbl` eu
        LEFT JOIN m_admin ma
        ON ma.admin_id = eu.interview_plan_staff
        WHERE delete_flg = 0 
        AND interview_plan_date LIKE '$year-$month%'
        AND CASE 
                WHEN (SELECT admin_flg FROM m_admin WHERE admin_id = {$login_id} AND delete_flg=0) = 0 THEN eu.interview_plan_staff = {$login_id} 
                WHEN {$id} <> 0 THEN eu.interview_plan_staff = {$id}
                ELSE TRUE 
            END
        GROUP BY DATE_FORMAT(interview_plan_date, '%Y%m%d')
        ";

1 个答案:

答案 0 :(得分:0)

如果是数据库错误,您可能首先打开显示错误,在Codeigniter中,您可以通过编辑index.php页面来改变环境到开发

 define('ENVIRONMENT', 'development');