我正在用PHP编写一个报告方法,它传递了两个参数$location$weekYear$weekYear是一个格式类似于2015-W34的字符串,即2015年第34周。我试图运行的sql代码如下:

   $sql = "SELECT
          CONCAT(tutor.first_name, ' ', tutor.last_name) AS Student,
          CONCAT(tutor.first_name, ' ', tutor.last_name) AS Tutor,
               hours as HoursWorked,
               DATE_FORMAT(work_date, '%a - %b %d') AS Day,
               DATE_FORMAT(start_time, '%H') AS Hour,
               DATE_FORMAT(start_time, '%i') AS Minute

          FROM timesheet_entry

          LEFT
          JOIN user
            AS student
            ON student.id = timesheet_entry.student_id

          LEFT
          JOIN user
            AS tutor
            ON tutor.id = timesheet_entry.tutor_id

         WHERE DATE_FORMAT(work_date,'%x-W%v') = '".$weekYear."'
           AND tutoring_location = '".$location."'
           AND work_type = 'instruction'
           AND (instruction_type = '1-on-1' OR instruction_type = 'group')";


        $query = $this->db->query($sql);

当我用php运行代码时,没有返回任何结果
但是,当我回显$sql并将其粘贴到PhpMyAdmin中时,我得到了预期的结果。
而且如果我把那部分去掉
DATE_FORMAT(work_date,'%x-W%v') = '".$weekYear."'

方法运行,返回的记录比我想要的多,但它仍然运行。
我的DATE_FORMAT()会导致这个查询出现故障吗?
任何帮助、建议和建议都非常感谢!

最佳答案

我想您应该为mysql和php创建一个函数,使用参数$location和$weekYear,因为您的参数weekYear与标准格式不同,而php或mysql不起作用

10-07 21:52