JohnnyKennedy Posted August 10, 2011 Share Posted August 10, 2011 Hey There, So I'm building a site, and part of this website allows users to message each other - I'm doing it through a PHP MySQL Database (I know it's probably not the best way :\ ). I've got an inbox, outbox, sent & the actual send function working, but what I can't figure out is how to tell if the message has been read or not. I was thinking of doing an integer kind of thing, for eg. I have a col in my database for 'read' with two possible values of 1 or 0 (1 being read, 0 being new). Then I played around with IF statements, but can't figure out how to do it. If you guys could maybe help me out with an IF statement that would let me show an Image if the value is 0. My Recordset was done using DW, and I have a repeat region included. Let me know what code you need, if you need any more - but heres the most relevant code. Thanks in advance you guys. $colname_inbox = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_inbox = $_SESSION['MM_Username']; } mysql_select_db($database_NewConnection, $NewConnection); $query_inbox = sprintf("SELECT * FROM mailboxes WHERE recipient = %s ORDER BY server_time DESC", GetSQLValueString($colname_inbox, "text")); $query_limit_inbox = sprintf("%s LIMIT %d, %d", $query_inbox, $startRow_inbox, $maxRows_inbox); $inbox = mysql_query($query_limit_inbox, $NewConnection) or die(mysql_error()); $row_inbox = mysql_fetch_assoc($inbox); Quote Link to comment https://forums.phpfreaks.com/topic/244429-mailbox-system-if-message-hasnt-been-read-display-image/ Share on other sites More sharing options...
TeNDoLLA Posted August 10, 2011 Share Posted August 10, 2011 I assume the users who receive the messages will click a link to read the message. You can add an UPDATE SQL to the code that handles the part when user wants to read a message and clicks the link. In this UPDATE you update the column 'read' to 1 for the message he just read. Quote Link to comment https://forums.phpfreaks.com/topic/244429-mailbox-system-if-message-hasnt-been-read-display-image/#findComment-1255434 Share on other sites More sharing options...
JohnnyKennedy Posted August 10, 2011 Author Share Posted August 10, 2011 Hey, Yep, sorry I forgot to mention that I figured that part out too. It's the IF statement that I'm confused about - you know, to check and display an image if the value of the Read column is ZERO. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/244429-mailbox-system-if-message-hasnt-been-read-display-image/#findComment-1255453 Share on other sites More sharing options...
darkfreaks Posted August 10, 2011 Share Posted August 10, 2011 add a "read" column as INT into your DB if($row['read']== NULL && $row['read']=='') { // column is empty no new inbox code here } else{ //you have new inbox code here } Quote Link to comment https://forums.phpfreaks.com/topic/244429-mailbox-system-if-message-hasnt-been-read-display-image/#findComment-1255456 Share on other sites More sharing options...
TeNDoLLA Posted August 10, 2011 Share Posted August 10, 2011 IF the 'read' field is 0 or 1 (int) maybe DEFAULT to 0. No need to compare to empty strings or null, just check the number of it. or even better just check against boolean if ($row['read']) { // Message is read } else { // Message not read } Quote Link to comment https://forums.phpfreaks.com/topic/244429-mailbox-system-if-message-hasnt-been-read-display-image/#findComment-1255457 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.