White_Lily Posted November 13, 2012 Share Posted November 13, 2012 Hi I have created an inbox system, but i want to implement a read/unread system. Messages would consist of 2 people always. (Sender & Receiver). I was wondering how I would go about this. (I would like to avoid javascript / jquery if possible) Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/ Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 You need to explain what you think you mean by "read/unread system". As I explained when you originally posted about the inbox system, you need to be clear about what you're trying to do, rather than assuming we can read your mind. What exactly do you want to accomplish? If you can explain it in plain english, you can probably figure out how to do it in PHP/MySQL. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392096 Share on other sites More sharing options...
White_Lily Posted November 13, 2012 Author Share Posted November 13, 2012 how can you explain a read/unread system for an inbox? A user has either read a message, or not read a message, however when a user sends a message to another, the receiver needs to see it as unread... im not entirely sure how else to explain it... Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392098 Share on other sites More sharing options...
Jessica Posted November 13, 2012 Share Posted November 13, 2012 So you've explained your specifications now. Messages are either read or unread. When someone looks at a message, you would change it to read. Where are you stuck??? What have you done? You're acting like it's some kind of magic system - you need to write the code. To write the code you need to be able to say what the code should do. It sounds like you have said what the code should do - now do it... Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392099 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 Um, tbh - if i knew how to go about doing it, I wouldn't be posting here... would I? Ass in, what does my database need in it as all it has at the moment is the simple things like; content, message id, from, to, subject... what else is needed? Maybe give me some links to look at or some sample code that I can build on, I have tried looking on the internet but nothing seems to do what I need it to do. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392165 Share on other sites More sharing options...
MDCode Posted November 14, 2012 Share Posted November 14, 2012 Just create a read field. Set it to Enum: '0','1' if a user has read it, update read set to 1. else keep it at 0. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392170 Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 It's just logic. You want to store if a message has been read or not. What would you add to your table? You want to store ONE THING that is a boolean. Is it really THAT HARD to figure out what you change in your table? You need to start thinking a little instead of assuming you'll find it on the internet. We are here to help but you are not doing any of this work on your own. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392174 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 I tried to use the 0 or 1 method but if its set to 0 then it comes up on both users as unread, and if it is set to one then it comes up on both users as read... even if they haven't read it. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392206 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 Then you didn't do a very good job of explaining the functionality that you were looking for. You said nothing about the sender still having visiblity of the message after it was sent, or having a read flag on the sender side (I assume you want that just incase they typed the message with their eyes closed?) I know it sounds like were all being a bit harsh and getting on your back here, but it is for your benefit that we are doing it. It's one of the most frustrating things (I personaly would put it right up there with a baby crying for no good reason) in the word when you get an unclear or ambiguous job spec. Please try and be as explicit and verbose about what you are looking for as you can be. That said - you gave the impression that you needed a single flag : you were then told to insert a single enum column (although bit would be just as good) - It turns out that you actulay want two flags....... Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392211 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 Okay so i made 2 columns in my database, "read_1" and "read_2", how would i go about defining which user has/hasn't read whatever messages? Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392226 Share on other sites More sharing options...
Muddy_Funster Posted November 14, 2012 Share Posted November 14, 2012 How about read_sender and read_recipient (I always find it nice when tables have relevent column names)? assuming you have both sender_id and a recipient_id stored in the table against the message then you simply check which of these two the current user id matches and update the table to set the relevent field accordingly. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392235 Share on other sites More sharing options...
winningdave Posted November 14, 2012 Share Posted November 14, 2012 My 2 cents: Database should look something like this : id | subject | body | sender | recipient | read When a new message is created "read" would be set to 0, when the user reads it that would be updated to 1. As far as how you go about it, its up to you. You said avoid Javascript in that case you could provide an "Inbox" list of message and when a user opens the full message , set the read field to 1... Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392262 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 winningdave good logic however the only problem with that is that if read is set to 0 then both users would see it as unread, and if it was set to 1 both users would see it as read, even if one of the users has NOT read the message. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392278 Share on other sites More sharing options...
Pikachu2000 Posted November 14, 2012 Share Posted November 14, 2012 How is it possible the sender would NOT have read it? Why even bother showing the sender the status? Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392280 Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 How is it possible the sender would NOT have read it? Why even bother showing the sender the status? That's what I'm confused about too - of course the sender read it, they wrote it. It should change from read to unread when the recipient reads it. I wonder if she's talking about a message thread like in Gmail? Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392289 Share on other sites More sharing options...
Manixat Posted November 14, 2012 Share Posted November 14, 2012 (edited) Showing the sender that the message is unread is actually good because that way the sender will know whether it has been read or not, however if you don't want this kind of functionality the easiest way is to check if it is the sender who is viewing the message at the time and not mark it as unread. because of my bad English I'm going to explain this in a simpler way in your php document do this retrieve the "read" value ( 0 or 1 ) from your db and using an IF statement checking if the current user is the sender don't apply styles for unread message Edited November 14, 2012 by Manixat Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392291 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 If the sender sends a message, then obviously they have read it, but the reciever may not have read it... in which case the message would appear bold in the reciever's inbox, but not bold in the sender's inbox. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392295 Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 Why would the message be IN the sender's INBOX? It should be in a SENT folder. If you're showing an "all messages" view (again, like gmail), you still don't show sent messages. When you're showing the sent messages, you wouldn't bold messages they sent unless you WANT to be able to show them it hasn't been read by the reader. If you for some odd reason want to show sent messages in an inbox, you would use logic in PHP to determine the bolding - if they are the one that sent it, you don't want it bold (based on your last post), so use that logic - not the read/unread field. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392298 Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2012 Share Posted November 14, 2012 The read/unread status only applies to the recipient. You would only use it for highlighting when the current user is the recipient, not when the current user is the sender. The messages in any user's 'in box' are when the current user = recipient. The messages in any user's 'out box' are when the user = sender. Messages someone sends aren't in their inbox. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392299 Share on other sites More sharing options...
Manixat Posted November 14, 2012 Share Posted November 14, 2012 so what's the problem ? in your IF statement that checks if the message is read add another comparison checking if current user is not equal to sender ?? Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392300 Share on other sites More sharing options...
White_Lily Posted November 14, 2012 Author Share Posted November 14, 2012 So basically I should re-code it so that sent messages get put into some kind of "sent" folder (or table since that where messages are stored)? Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392304 Share on other sites More sharing options...
Jessica Posted November 14, 2012 Share Posted November 14, 2012 Not a separate table - the php script that displays the messages should have options. You would select a folder, and the script would show you the messages in that folder. Common default folders would be Inbox and Sent. Also Trash sometimes. The script then uses simple logic to determine which messages to display from your single table. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392309 Share on other sites More sharing options...
AyKay47 Posted November 14, 2012 Share Posted November 14, 2012 You have been given several answers to this issue already. Not much more anyone can do for you. Apply the advice that was given to you and if you are still having issues with the code after you have attempted to implement the logic given to you, post back with all relevant code and your issue. Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1392314 Share on other sites More sharing options...
Zombie123 Posted May 30, 2014 Share Posted May 30, 2014 Hi , hello zombie here , i also want to create this INBOX SYSTEM too but i'm a little bit confuse with some php code .can anybody help me ? please ... thank you . i already start some code . i just now need to connect this into database so that all unread emails will be going to write to database . what code i will use ? hihi ... i'm a newbie :)really appreciate with ur help im ----------------------------------------------------- <?php function unread_emails ($username , $password){ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'UNSEEN'); echo count($emails)." "; echo "<pre>".print_r($emails,true)."</pre>"; //die; /* if emails are returned, cycle through each... */ if($emails) { $i=0; /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { $i++; /* get information specific to this email */ $overview = imap_fetch_overview($inbox,$email_number,0); $message = imap_fetchbody($inbox,$email_number,1); /* output the email header information */ $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; $output.= '<span class="from">'.$overview[0]->from.'</span>'; $output.= '<span class="date">on '.$overview[0]->date.'</span>'; $output.= '</div>'; /* output the email body */ $output.= '<div class="body">'.$message.'</div>'; //if{$i==10} break; } echo $output; } /* close the connection */ imap_close($inbox); } unread_emails ('**********@gmail.com' , '*******' ); ?> Link to comment https://forums.phpfreaks.com/topic/270638-readunread-messages/#findComment-1481343 Share on other sites More sharing options...
Recommended Posts