这让我很生气。
我的查询忽略了WHERE子句,只输出了所有结果。
我知道它仍在阅读脚本,因为当我将脚本更改为荒谬的东西时,例如WHERE user = xxx会抛出错误。
帮助?
$data = mysql_query(
"SELECT
tbl_messages.id as msgID,
tbl_messages.from_user as msgFROM,
tbl_messages.to_user as msgTO,
tbl_messages.the_message as msgMESSAGE,
tbl_messages.status as msgSTATUS,
tbl_messages.date as msgDATE,
tbl_messages.subject as msgSUBJECT,
tbl_users.id as usrID,
tbl_users.name as usrNAME,
tbl_photos.profile as photosPROFILE,
tbl_photos.photo_link as photoLINK,
tbl_photos.default_photo as photoDEFAULT
FROM tbl_messages
LEFT JOIN tbl_users
ON tbl_messages.from_user = tbl_users.id
LEFT JOIN tbl_photos ON tbl_photos.profile = tbl_users.id
WHERE tbl_messages.to_user = 65 AND tbl_photos.default_photo IS NULL OR tbl_photos.default_photo = '1'
ORDER BY status DESC")
答案 0 :(得分:1)
这只是猜测,但你可能需要围绕WHERE
子句的部分内容;它可能正在评估所有行的true
,如所写的那样。
WHERE tbl_messages.to_user = 65
AND (tbl_photos.default_photo IS NULL OR tbl_photos.default_photo = '1')
答案 1 :(得分:0)
我认为你也需要它看起来像这样:
WHERE tbl_messages.to_user = 65
AND tbl_photos.default_photo ='NULL' OR tbl_photos.default_photo = 1
ORDER BY status DESC
或者像这样:
WHERE tbl_messages.to_user = 65
AND tbl_photos.default_photo ='NULL' OR tbl_photos.default_photo = '1'
ORDER BY status DESC