[syntax=php]
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) //it will =1 if it's true
);
}
return $conversations;
}
function create_conversation($user_ids, $subject, $body){
$subject = mysql_real_escape_string(htmlentities($subject));
$body = mysql_real_escape_string(htmlentities($body));
mysql_query("INSERT INTO conversations (conversation_subject) VALUE ('{$subject}')");
$conversation_id = mysql_insert_id();
$sql = "INSERT INTO conversations_messages (conversation_id, user_id, message_date, message_text) VALUES ({$conversation_id}, {$_SESSION['user_id']}, UNIX_TIMESTAMP(), '{$body}')";
mysql_query($sql);
$values = array();
$user_ids[] = $_SESSION['user_id'];
foreach($user_ids as $user_id){
$user_id = (int) $user_id;
$values[] = "({$conversation_id}, {$user_id}, 0, 0)";
}
$sql = "INSERT INTO conversations_members (conversation_id, user_id, conversation_last_view, conversation_deleted) VALUE " . implode(", ", $values);
mysql_query($sql);
}
//check to see if the given user is a member of the given conversation.
function validate_conversation_id($conversation_id){
$conversation_id = (int)$conversation_id;
$sql = "SELECT COUNT(1)
FROM conversations_members
WHERE conversation_id = {$conversation_id}
AND user_id = {$_SESSION['user_id']}
AND conversation_deleted = 0";
$result = mysql_query($sql);
return (mysql_result($result, 0) == 1);
}
function delete_conversation($conversation_id){
$conversation_id = (int)$conversation_id;
$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";
$result = mysql_query($sql);
if(mysql_num_rows($result) === 1 && mysql_result($result, 0) == 1){
mysql_query("DELETE FROM conversations WHERE conversation_id = {$conversation_id}");
mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");
mysql_query("DELETE FROM coversations_messages WHERE conversation_id = {$conversation_id}");
} else {
$sql = "UPDATE conversations_members
SET conversation_deleted = 1
where conversation_id = {$conversation_id}
AND user_id = {$_SESSION['user_id']}";
mysql_query($sql);
}
}
[/syntax]
I check over and over and all code is correct, not sure why this happen.
ERROR:
( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\betterPHP\private_message_system\core\inc\private_message.inc.php on line 97
Private message system PART 11 error
Re: Private message system PART 11 error
Could be wrong but for database stuff shouldnt you be using ' ' in there like below?
mysql_query("DELETE FROM 'conversations' WHERE 'conversation_id' = {$conversation_id}");
mysql_query("DELETE FROM 'conversations' WHERE 'conversation_id' = {$conversation_id}");
Re: Private message system PART 11 error
Adding[syntax=php]echo mysql_error();[/syntax] under the query that is failing should tell you what's wrong.
Re: Private message system PART 11 error
Temor wrote:Adding[syntax=php]echo mysql_error();[/syntax] under the query that is failing should tell you what's wrong.
after when i echo mysql_error(); there is nothing happen, and it appear the same error message.
- Attachments
-
- echo.jpg (50.38 KiB) Viewed 888 times
Re: Private message system PART 11 error
where did you put the mysql_error(); line?
The problem appears to be at the second delete query.
[syntax=php] mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");[/syntax]
I would suggest you start adding backticks around your tables and rows. Like this:
[syntax=php] mysql_query("DELETE FROM `conversations_members` WHERE `conversation_id` = {$conversation_id}");[/syntax]
Are all the table and column names spelled correctly? Compare it with the names in phpmyadmin.
The problem appears to be at the second delete query.
[syntax=php] mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");[/syntax]
I would suggest you start adding backticks around your tables and rows. Like this:
[syntax=php] mysql_query("DELETE FROM `conversations_members` WHERE `conversation_id` = {$conversation_id}");[/syntax]
Are all the table and column names spelled correctly? Compare it with the names in phpmyadmin.
Re: Private message system PART 11 error
Temor wrote:where did you put the mysql_error(); line?
The problem appears to be at the second delete query.
[syntax=php] mysql_query("DELETE FROM conversations_members WHERE conversation_id = {$conversation_id}");[/syntax]
I would suggest you start adding backticks around your tables and rows. Like this:
[syntax=php] mysql_query("DELETE FROM `conversations_members` WHERE `conversation_id` = {$conversation_id}");[/syntax]
Are all the table and column names spelled correctly? Compare it with the names in phpmyadmin.
Hi, I put mysql_error(); in line 96, and after i test it, it have the same result. than i try again put it at line 99, also having the same error.
Also tried to put all the backticks around the tables, and i did check the spelling it match them all. Please check the attachment.
- Attachments
-
- Untitled-1.jpg (56.37 KiB) Viewed 883 times
Re: Private message system PART 11 error
Hmm, the line number suggests that this is the failing query
[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";
$result = mysql_query($sql);[/syntax]
if you added the mysql_error() like this
[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";
$result = mysql_query($sql);
echo mysql_error();[/syntax]
it should have worked.
You could also try running that query in phpmyadmin to see what's going on.
[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";
$result = mysql_query($sql);[/syntax]
if you added the mysql_error() like this
[syntax=php]$sql = "SELECT DISTINCT conversation_deleted
FROM conversation_members
WHERE user_id != {$_SESSION['user_id']}
AND conversation_id = {$conversation_id}";
$result = mysql_query($sql);
echo mysql_error();[/syntax]
it should have worked.
You could also try running that query in phpmyadmin to see what's going on.
Re: Private message system PART 11 error
THANK YOU,, I FIGURE IT ALREADY, I MISSED A (S)
Last edited by jacek on Fri Jun 22, 2012 1:27 am, edited 1 time in total.
Reason: Removed massive quote.
Reason: Removed massive quote.