0

这让我现在快疯了。

我的查询忽略了 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")
4

2 回答 2

0

WHERE这只是一个猜测,但您可能需要在子句的某些部分加上括号;true如所写,它可能正在评估所有行。

WHERE tbl_messages.to_user = 65
    AND (tbl_photos.default_photo IS NULL OR tbl_photos.default_photo = '1')
于 2013-08-29T15:51:49.023 回答
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
于 2014-02-22T00:38:09.617 回答