【发布时间】:2014-02-14 06:23:57
【问题描述】:
我有以下代码:
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 和 MySQL 完全陌生,但是我尝试过检查拼写错误,回显 mysql_error,并在出现错误时终止脚本,这表明 SQL 中没有错误。
我不知道出了什么问题以及如何解决它。
请帮助我。提前致谢。
【问题讨论】:
-
您的查询好像失败了?
-
我是这么想的,但我看不出怎么做;你有什么想法吗?
-
尝试
echo count($messages);if print 0 no result is found in your query -
我做到了,但我得到的只是资源(16)类型(mysql结果)0
标签: php mysql sql arrays output