简体   繁体   中英

PHP - Query works locally but not on server

I am using the following query to get information about a student, a goal they have set, what standard it connects with, and what their current grade is for that standard.

There can be more than one grade per standard and I want the most recent one so I added a subquery to get the most recent date.

The code works well when I test it in XAMPP but does not load on my server. The databases are identical and I am not sure what else could be the problem.

SELECT users.firstName, goals.goalgrade, 
standards.standard, goals.why, grades.grade                                 
FROM users
    LEFT JOIN goals ON goals.userid = users.id
    LEFT JOIN standards ON standards.id = goals.mid
    LEFT JOIN grades ON grades.testId = standards.standard
        AND grades.userId = users.id
        AND grades.date = (SELECT date FROM grades ORDER BY date DESC LIMIT 1)
WHERE users.teacherId = :teacherId
AND users.block = :block
ORDER BY $sortall

I fixed the problem, figured I would share. The subquery with XAMPP was fine with date being by itself but the server needed me to add the table name I changed:

   grades.date = (SELECT date FROM grades ORDER BY date DESC LIMIT 1)

To:

AND grades.date = (SELECT grades.date FROM grades ORDER BY grades.date DESC LIMIT 1)

My server says it is running MySQL 5.0 while XAMPP is running MySQL 5.1.44. Not sure if this would make a difference but it worked. Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM