Ashoar Posted January 9, 2009 Share Posted January 9, 2009 I have my private message inbox code code here. At the moment when you recieve a message you dont get a notification, you have to manually go into the inbox and find the new message. I cant figure it out, could someone help me show unread and read messages and how to add a notification when you recieve a new message so that i can add the new message notification to the members profile page. <?php session_start(); require_once("header.php"); $user = $_SESSION['username']; include 'db.php'; if(!$user) { echo "<br><p>You arent logged in, Please login or Register</p><br>"; } else { $sql = mysql_query ("SELECT pm_count FROM members WHERE username='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; $percent = $pm_count/'50'; $percent = $percent * '100'; ?> <br> <center> <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b> <b><p><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b> </center> <br> <?php $query = "SELECT id, sender, subject, message FROM messages WHERE reciever='$user'"; $sqlinbox = mysql_query($query); if(!$sqlinbox) { ?> <p><?php print '$query: '.$query.mysql_error();?></p> <?php } elseif (!mysql_num_rows($sqlinbox) ) { ?> <center><p><b>You have no messages to display</b></p></center> <?php } else { ?> <center> <form name="send" method="post" action="delete.php"> <table width="80%"> <tr> <td width="75%" valign="top"><p><b><u>Subject</u></b></p></td> <td width="120px" valign="top"><p><b><u>Sender</u></b></p></td> <td width="25px" valign="top"><p><b><u>Select</u></b></p></td> </tr> <?php while($inbox = mysql_fetch_array($sqlinbox)) { $pm_id = $inbox['id']; $sender = $inbox['sender']; $subject = $inbox['subject']; ?> <tr> <td width="75%" valign="top"><p><a href="viewmsg.php?msg_id=<?php echo $pm_id; ?>"><?php echo $subject; ?></a></p></td> <td width="120px" valign="top"><p><?php echo $sender; ?></p></td> <td width="25px" valign="top"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>"></td> </tr> <?php } ?> <tr> <td colspan="3"><input type="submit" name="Submit" value="Delete Selected"></td> <td></td> <td></td> </tr> </table> </center> <?php } } require_once("footer.php"); ?> Thanks Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/ Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 Can I see your table structure? Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733258 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Yeah sure. CREATE TABLE `messages` ( `id` int(11) NOT NULL auto_increment, `reciever` varchar(25) NOT NULL default '', `sender` varchar(25) NOT NULL default '', `subject` text NOT NULL, `message` longtext NOT NULL, `recieved` enum('0','1') NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733260 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 ok, I'd add another field and call it something like `new_msg` Make it able to take a 1 or 0, this can act as a boolean value. When a message is sent inset a 1, once it is read change it to 0 Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733262 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Ok thanks ill add it in and test it out and let you know the results. Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733266 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Update. Ok i have updated the database with the new field. Now going back to the php inbox code, what exactly do i need to add to it so that it knows of the new messages and allows me to echo a notification> The new field name is, newmsg Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733273 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 you check if newmsg = 1, if it does you have a new message Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733276 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 I can do that part, but shouldnt i need to add something to the php code so that the database field knows when a message is recieved? Because at the moment there is nothing in the code with the name newmsg Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733278 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 You have to add the code that checks newmsg in the database with the user's id to see if there are any new messages Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733279 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Could you show me how Really unsure of how i am to do that Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733280 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 Ok, so at the moment, if someone sends a message you set newmsg to 1? Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733285 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 The newmsg field on the database is Default 1. So yes Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733288 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 ok, the following will check the database SELECT COUNT(id) AS `newmessages` FROM messages WHERE received='$user' && newmsg=1 Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733291 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Ok yeah i understand that part Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733295 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 what else you need to know? Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733298 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Ok ill try it out now. Also is this correct for the database field? `newmsg` enum('1','0') NOT NULL default '1', Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733299 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 yea that's cool Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733305 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Have a problem, with that piece of code in i get this error. Parse error: syntax error, unexpected T_STRING in /home/a4588739/public_html/inbox.php on line 31 Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733310 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 which piece of code? lol Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733312 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 This 1 you said SELECT COUNT(id) AS `newmessages` FROM messages WHERE received='$user' && newmsg=1 Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733315 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 mysql_query("SELECT COUNT(`id`) AS `newmessages` FROM `messages` WHERE received='$user' && newmsg='1'"); see if thats better Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733318 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 Yep that was better. And under that do i need to put something like: if (newmsg='1') <p><?php echo "You have new messages" ?></p> so that it says if you have a new message or not, because adding that give another error Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733327 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 have you used php and mysql much before? Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733336 Share on other sites More sharing options...
Ashoar Posted January 9, 2009 Author Share Posted January 9, 2009 yes, through tutorials Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733348 Share on other sites More sharing options...
gevans Posted January 9, 2009 Share Posted January 9, 2009 so you know you have to fetch the results of a query, and get the return values from that array? Link to comment https://forums.phpfreaks.com/topic/140142-pm-notification/#findComment-733351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.