Jump to content

MYSQL retrieve question


depojones

Recommended Posts

Hello,

 

I have a chat application that is working currently, but am thinking of a way to improve on it. What am trying to do is this; I want when a new user log in, he cannot see what has been said (chat-about) before his arrival. How do i go about it.

 

Thanks in advance

Link to comment
Share on other sites

This really depends on your implementation but I tend to use flags for this type of thing. You can set a 'new flag' in the database that gets removed once the active users have all been sent the message. You would then only need to pull the 'new' messages every time and the old ones will never display for anyone that was not previously logged in.

Link to comment
Share on other sites

Yes, you would have to add in an extra field if you do not already have one.

 

It's hard to produce example code when I don't know how you're doing it now but here's a very simple example:

<?PHP
function retreiveMsg()  {
$sql = "SELECT * FROM messages WHERE new = '1'";
$result = mysql_query($sql);
$msg = mysql_fetch_array($result);
broadcast($msg);
}

function broadcast(array $msg) {
$chat->active_users->sendmsg($msg);
removeflag($msg['uid']);
}

function removeFlag($uid) {
$sql = "UPDATE messages SET new = '0' WHERE uid = '".$uid."'";
mysql_query($sql);
}

?>

 

This way it would select only the 'new' messages and send it to the active users in the current chat session.

As a new user enters they would only see the newest ones from the time they joined the active users.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.