-1
我的代碼,這個功能寫在我的網站上顯示用戶消息:SELECT查詢「大於」無法正常工作?
function fetch_conversation_summery(){
$sql = "SELECT
`conversations`.`conversation_id`,
`conversations`.`conversation_subject`,
MAX(`conversations_messages`.`message_date`) AS `conversation_last_reply`
MAX(`conversations_messages`.`message_date`) > `conversations_members`.`conversation_last_view` AS `conversation_unread`
FROM `conversations`
LEFT JOIN `conversations_messages` ON `conversations`.`conversation_id` = `conversations_messages`.`conversation_id`
INNER JOIN `conversations_members` ON `conversations`.`conversation_id` = `conversations_members`.`conversation_id`
WHERE `conversations_members`.`userid` = {$_SESSION['userid']}
AND `conversations_members`.`conversation_deleted` = 0
GROUP BY `conversations`.`conversation_id`
ORDER BY `conversation_last_reply` DESC";
$result = mysql_query($sql);
$conversations = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$conversations[] = array(
'id' => $row['conversation_id'],
'subject' => $row['conversation_subject'],
'last_reply' => $row['conversation_last_reply'],
'unread_messages' => ($row['conversation_unread'] == 1),
);
}
return $conversations;
}
雖然當我嘗試使用這個正確的頁面上,它會發出一個錯誤:
mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in...
我所在問題是在查詢中,在該行:
MAX(`conversations_messages`.`message_date`) > `conversations_members`.`conversation_last_view` AS `conversation_unread`
雖然似乎有什麼我可以看到不對的地方,所有的表名是CORRE CT仍然是一個錯誤?有沒有人有任何想法可能造成這種情況?
P.S代碼工作正常,沒有我提到錯誤所在的MAX行。
什麼數據類型是你的'message_date'列? –
message_date是一個10的INT。 – user257234
嘗試在運行查詢後添加'echo mysql_error();'。另外,你有沒有試圖用phpmyadmin(或其他應用程序)對數據庫運行查詢? –