depojones Posted May 27, 2010 Share Posted May 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203066-mysql-retrieve-question/ Share on other sites More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203066-mysql-retrieve-question/#findComment-1064034 Share on other sites More sharing options...
depojones Posted May 27, 2010 Author Share Posted May 27, 2010 At the moment, am pulling all messages from the database once a user logs in. Do I need to create an extra field in the chat table. Kindly provide me with some example code. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/203066-mysql-retrieve-question/#findComment-1064037 Share on other sites More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203066-mysql-retrieve-question/#findComment-1064043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.