Can someone look at the following code and help me. The code works perfect except that it displays the user who sends a message the number of times of messages they sent. i.e. tom(3) tom(3) tom(3)
What am I missing in the code to get it to show it only once.
Thanks
//get all users
$sql = "SELECT * FROM message where recipient = '$username'";
$result=mysql_query($sql, $connection);
while ($myrow = mysql_fetch_array($result))
{
$sender = $myrow['sender'];
$recipient = $myrow['recipient'];
// show name of friend
echo "<a href=\"messenger/send.php?sender=$contact_username2&recipient=$sender\"><font color=\"$linkcolor\">$myrow[sender]</font></a>";
// count all mesages for this user
$sql = "SELECT count(*) as aantal FROM message where recipient = '$username' AND sender = '$myrow[sender]'";
$messageresult=mysql_query($sql, $connection);
$myrow2 = mysql_fetch_array($messageresult);
if ($myrow2[aantal] <> 0)
{
$sql = "SELECT isread FROM message where recipient = '$username' AND sender = '$myrow[sender]' AND isread=0";
$readmessageresult=mysql_query($sql, $connection);
$myrow3 = mysql_fetch_array($readmessageresult);
echo " <a href=\"messenger/messages.php?sender=$contact_username2\">";
if ($myrow3[isread] == null)
{
echo "<font color=\"$oldmessagecolor\">(". $myrow2[aantal] . ")</font></a>";
}else{
echo "<font color=\"$newmessagecolor\">(". $myrow2[aantal] . ")</font></a>";
}
}
}
$contact_username2 is what I'm using in a different sql query to keep the names seperated between sender and recipient.
Thanks,
Michael