Hi guys,
I have created a litle PM system on my website, it shows me my sent box and everything works just fine, but I have a question;
In my Database I have a field called ‘recieved’ it can hava either value 1 or 0, if 0 means the message is not read yet, if 1 its read by the reciever. So I wanna show this to the sender.
So when he goes to the sent box he sees the subject and if message is not read it will say so, like this;
[Message Subject here] (Unread)
If its read it will just be like
[Message Subject here]
The question is; how do I create a code that shows so? Heres my current code:
<?php
session_start();
$username = $_SESSION['username'];
require_once("header.php");
include 'functions/DbConnector.php';
//Are they logged in or not?
if(isLoggedIn() == false)
{
show_loginform();
}
else
{
//Get your private message count
$sql = mysql_query ("SELECT pm_count FROM login WHERE username='$username'");
$row = mysql_fetch_array ($sql);
$pm_count = $row['pm_count'];
$percent = $pm_count/'50';
$percent = $percent * '100';
?>
<br>
<center>
<b><p><h3><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b>
<b><p></h3><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b>
</center>
<br>
<?php
//Get all message that are sent by the logged in user, and that have the recieved field set to zero, meaning they have not been recieved, once read the view message page sets the recieved field for the message to 1
$query = "SELECT * FROM messages WHERE sender='$username' ORDER BY id DESC LIMIT 10";
$sqlinbox = mysql_query($query);
//If there is a MySQL error we need to display the error because something has gone horribly wrong on the server.
if(!$sqlinbox)
{
?>
<p><?php print '$query: '.$query.mysql_error();?></p>
<?php
}
//If all messages sent by the user were recieved or deleted, then just say that there are no messages not recieved
elseif (!mysql_num_rows($sqlinbox) )
{
?>
<p><b>You have no sent messages to display</b></p>
<?php
}
//If there are messages that have not been recieved yet we need to display those messages to the user
else
{
//Lets make a table for the messages to go in, to keep things organised and such
?>
<table width="100%" border="0">
<tr>
<td width="" valign="top"><p><b><u>Subject</u></b></p></td>
<td width="120px" valign="top"><p><b><u>Sent to</u></b></p></td>
<td width="120px" valign="top"><p><b><u>Time</u></b></p></td>
</tr>
<?php
//This is a while loop that goes through the array while there are still things in it, getting the subject and reciever and displaying them
while($inbox = mysql_fetch_array($sqlinbox))
{
$reciever = $inbox['reciever'];
$subject = $inbox['subject'];
$timesendt= $inbox['timesendt'];
?>
<tr>
<td width="" valign="top"><p><?php echo "$subject"; ?></p></td>
<td width="120px" valign="top"><p><?php echo "$reciever"; ?></p></td>
<td width="120px" valign="top"><p><?php echo "$timesendt"; ?></p></td>
</tr>
<?php
}
echo "</table>";
}
}
require_once("footer.php");
?>