我有以下代碼:PHP的var_dump返回reesource(16)
function fetch_conversation_messages($conversation_id){
$conversation_id = (int)$conversation_id;
$sql = "SELECT
`conversations_messages`.`message_date`,
`conversations_messages`.`message_date` > `conversations_members`.`conversation_last_view` AS `message_unread`,
`conversations_messages`.`message_text`,
`users`.`user_name`
FROM `conversations_messages`
INNER JOIN `users` ON `conversations_messages`.`user_id` = `users`.`user_id`
INNER JOIN `conversations_members` ON `conversations_messages`.`conversation_id` = `conversations_members`.`conversation_id`
WHERE `conversations_messages`.`conversation_id` = {$conversation_id}
AND `conversations_members`.`user_id` = {$_SESSION['user_id']}
ORDER BY `conversations_messages`.`message_date` DESC";
$result = mysql_query($sql);
var_dump($result);
$messages = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$messages[] = array(
'date' => $row['message_date'],
'unread' => $row['message_unread'],
'text' => $row['message_text'],
'user_name' => $row['user_name'],
);
}
var_dump($messages);
}
它應該返回是這樣的:
Array ([0] => Array ([date] => 1322254667 [text] => one [user_name] => bob))
然而,返回
resource(16) of type (mysql result) array(0) { }
我完全不熟悉PHP a nd MySQL,但我嘗試檢查錯誤,回顯mysql_error,並在發生錯誤時終止腳本,這表明SQL中沒有錯誤。
我不知道出了什麼問題以及如何解決問題。
請幫幫我。提前致謝。
似乎您的查詢失敗? –
我以爲但我看不到;你有什麼想法? – user3308065
用'echo count($ messages)嘗試;'如果print 0沒有在你的查詢中找到結果 – 2014-02-14 06:27:58