liamloveslearning Posted May 23, 2008 Share Posted May 23, 2008 Hi all, i have a problem with my inbox, when a user reads his message it updates my enumerated field in my table to 1 (0 being unread, 1 being read) however, in my table on my page my "status" column shows the number in my table rather than read and unread. Im just wondering to do this, is it just a basic recordset? heres my code <?php session_start(); $user = $_SESSION['kt_login_id']; //Are they logged in or not? if(!$user) { echo "<br><p>Blah blah you arent logged in and stuff, you should do that or something</p><br>"; } else { //Get your private message count //Find the percentage that your inbox is full $sql = mysql_query ("SELECT pm_count FROM members WHERE member_id='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; $percent = $pm_count/'50'; $percent = $percent * '100'; ?> <p class="profilehdr">Mail Center<br />Inbox<br /> <?php //This stuff and the while loop will query, see if you have messages or not, and display them if you do $query = "SELECT id, sender, subject, message, datetime, recieved FROM messages_test WHERE reciever='$user'"; $sqlinbox = mysql_query($query); //Error thingy, ohh no! Dispaly the error and the query so we can diagnose the problem if there is one if(!$sqlinbox) { ?> <?php print '$query: '.$query.mysql_error();?> <?php } //There are no rows found for the user that is logged in, so I guess that means they dont have any messages or maybe its all broken elseif (!mysql_num_rows($sqlinbox) ) { ?> <center> <p class="profilehdr"><b>You have no messages to display</b> <?php } //So if there is not an error, and they apparently do have messages we need to get their information and display it. else { //Ok, Lets center this whole table Im going to make just because I like it like that //Then we create a table 80% the total width with 3 columns The subject is 75% of the whole table, the sender is 120 pixels (should be plenty) and the select checkboxes only get 25 pixels ?> <form name="send" method="post" action="delete.php"> </p> <table width="100%"> <tr valign="middle"> <td width="4%" class="message_header">Check</td> <td width="16%" class="message_header">Date</td> <td width="145px" class="message_header">From</td> <td width="9%" class="message_header">Status</td> <td width="145px" class="message_header">Subject</td> </tr> <?php //Ok cool, now we stick it all into an array and we will dispaly it now while($inbox = mysql_fetch_array($sqlinbox)) { //These are the variables we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it $pm_id = $inbox['id']; $sender = $inbox['sender']; $subject = $inbox['subject']; $datetime = $inbox['datetime']; $recieved = $inbox['recieved']; //So lets show the subject and make that a link to the view message page, we will send the message id through the URL to that page so it can be displayed //And also let the person wee who sent it to them, if you want you can make that some sort of a link to view more stuff about the user, but Im not doing that here, I did it for my game though, pretty much same as the viewmsg.php page but a different page, and with the senders id //And finally the checkboxes that are all stuck into an array and if they are selected we stick the private message id into the array //I will only let my users have a maximum of 50 messages, remeber that ok? Because that's the value I will use later for things ?> <tr valign="middle"> <td width="4%" align="center" class="message_rows"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>" /></td> <td width="16%" align="left" class="message_rows"><?php echo $datetime; ?></td> <td class="message_rows"><?php echo $sender; ?></td> <td width="9%" class="message_rows"><?php echo $recieved; ?></td> <td class="message_rows"><a href="mail_viewmsg.php?msg_id=<?php echo $pm_id; ?>" class="message_rows_subject"><?php echo $subject; ?></a></td> </tr> <?php //This ends the while loop } ?> <tr> <td height="10" colspan="7"></td> </tr> <tr valign="middle"> <td colspan="7"><table class="footerCell" width="100%" cellpadding="0" cellspacing="0"> <tr> <th align="left" valign="middle" bgcolor="#6698CB" style="padding-left:8px"></th> <th colspan="3" align="right" bgcolor="#6698CB"> <input name="Submit" type="submit" value="Delete Selected" /> </th> </tr> </table></td> </tr> </table> <?php //So this ends the else to see if it is all ok and having messages or not } //This ends that first thing that checks if you are logged in or not } ?> Link to comment https://forums.phpfreaks.com/topic/106989-solved-recordset-query/ Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 if the value of the field is 1, echo read, else echo unread. echo ($read == 1)?"read":"unread"; Link to comment https://forums.phpfreaks.com/topic/106989-solved-recordset-query/#findComment-548396 Share on other sites More sharing options...
liamloveslearning Posted May 23, 2008 Author Share Posted May 23, 2008 ahh okay thanks, can i just ask == means is equal to? im new to this so still trying to understand it all, thanks Link to comment https://forums.phpfreaks.com/topic/106989-solved-recordset-query/#findComment-548398 Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 yes. that line says, echo the result of (if $read is equal to 1, then "read", else "unread") Link to comment https://forums.phpfreaks.com/topic/106989-solved-recordset-query/#findComment-548401 Share on other sites More sharing options...
liamloveslearning Posted May 23, 2008 Author Share Posted May 23, 2008 ahh brilliant, that solved it; thanks a lot ! Link to comment https://forums.phpfreaks.com/topic/106989-solved-recordset-query/#findComment-548402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.