0
我有這個很長的mysql查詢,並試圖找到獲取行比較老,然後給出日期$lastmsg
。在mysql中處理日期?
這是使用的代碼IM:
$result="SELECT
u.username, u.picture,m.id, m.user_note, m.reply_id, m.reply_name, m.recycle_id, m.recycle_name, m.dt
FROM
relationships r,
notes m,
user u
WHERE
m.user_id = r.leader
AND
r.leader = u.user_id
AND
r.listener = ".$_SESSION['user_id']."
UNION
select username, picture,id, user_note, reply_id, reply_name, recycle_id, recycle_name, dt
from user u, notes b
where u.user_id = b.user_id
AND
b.user_id =".$_SESSION['user_id']."
AND
WHERE dt < '$lastmsg'
ORDER BY dt DESC LIMIT 10";
mysql_query($result) or die(mysql_error().$result);
抱歉長亂碼,查詢工作,直到我加入這個$ lastmsg where子句。
p.s. dt爲DATETIME
和$ lastmsg是2010-09-20 12:53:43
錯誤即時得到的是:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where dt <'2010-09-20 12:53:43' ORDER BY dt DESC LIMIT 10' at line 20SELECT u.username, u.picture,m.id, m.user_note, m.reply_id, m.reply_name, m.recycle_id, m.recycle_name, m.dt FROM relationships r, notes m, user u WHERE m.user_id = r.leader AND r.leader = u.user_id AND r.listener = 2 UNION select username, picture,id, user_note, reply_id, reply_name, recycle_id, recycle_name, dt from user u, notes b where u.user_id = b.user_id and b.user_id =2 and where dt <'2010-09-20 12:53:43' ORDER BY dt DESC LIMIT 10
如果'$ lastmasg' =='2010-09-20 12:53:43''多餘的引用會導致語法錯誤。 mysql報告的錯誤是什麼? – Wrikken 2010-09-20 17:06:55
我剛編輯我的問題,錯誤是他們! – getaway 2010-09-20 17:08:14