Page 1 of 1

Private Message System

Posted: Sun Dec 04, 2011 7:09 pm
by jnaz
Hello

I have a problem with my query on part 9 of the series. It dosn't return any value.
I have try to use the mysql_error function but dosn't give me back and value.
I have a error like Resource id #9, what does that mean?
Also i got this error: 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 'MAX.


Here is the code.
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` . `user_id` = {$_SESSION['user_id']}
				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;
}
thanks

Re: Private Message System

Posted: Sun Dec 04, 2011 10:02 pm
by jacek
jnaz wrote:I have a error like Resource id #9, what does that mean?
That is the internal resource Id. The link to the mysql server is a resource. don’t worry about that too much ;)
jnaz wrote:Also i got this error: 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 'MAX.
That is the output from the msyql_error() function, where did you use that function ? I can't see any problems with the code you posted right away so that error could be coming from somewhere else.

Actually, I just ran your SQL with my table from the tutorial and it worked fine. so the problem must be from another query.

Re: Private Message System

Posted: Mon Dec 05, 2011 1:05 am
by jnaz
Thanks for reply. I've solve the problem now, did cheak the database and i notice a 0 as number on conversation_id.
Did seem abit odd, after that i saw a type error on function create_conversation, after thats been fix everthing work. :)