0

这个查询:

$user_mail_all=mysql_query("SELECT * 
FROM `mailing` WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' ORDER BY `id` DESC  LIMIT ".$start.",".$per_page )

运行良好,但下一个查询:

$user_mail_all=mysql_query("SELECT * 
FROM `mailing`WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' 
LEFT JOIN `mail_views` 
ON mailing.id=mail_views.lid 
AND mail_views.uid=".$_SESSION['uid']." 
ORDER BY `id` DESC  LIMIT ".$start.",".$per_page)

导致错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“LEFT JOIN mail_views ON mailing.id=mail_views.lid AND mail_views.uid=12 ORDER”附近使用正确的语法

为什么?

4

2 回答 2

1

先加入再匹配

$user_mail_all=mysql_query("SELECT * 
FROM `mailing`
LEFT JOIN `mail_views` 
ON mailing.id=mail_views.lid 
WHERE MATCH (resp) 
AGAINST ('$user_resp' IN BOOLEAN MODE) 
OR `cor`='$username' 
AND mail_views.uid=".$_SESSION['uid']." 
ORDER BY `id` DESC  LIMIT ".$start.",".$per_page)
于 2013-01-12T17:44:38.897 回答
0

在您的左连接查询实现中是错误的......它应该是:

select * from Table1 left join table2 where .....

所以用这个:

           $user_mail_all=
                mysql_query(
                             "SELECT * 
                                FROM `mailing`
                           LEFT JOIN `mail_views` 
                                 ON ( mailing.id=mail_views.lid 
                                     AND mail_views.uid=".$_SESSION['uid']".)
                              WHERE MATCH (resp) 
                                    AGAINST ('$user_resp' IN BOOLEAN MODE) 
                                 OR `cor`='$username'
                           ORDER BY `id` DESC  LIMIT ".$start.",".$per_page);
于 2013-01-12T18:03:09.123 回答