...

View Full Version : Privare Messaging Code help



graham23s
08-07-2007, 07:34 PM
Hi Guys,

what i'm trying to do here is turn the word "inbox" red if the messages have all been read and blue if there is messages in there that are unread my code is:


<?php
// Get the users details from mysql...//////////////////////////////////////////////
$query_1 = "SELECT * FROM `membership` WHERE `username`='$member'";
$result_1 = mysql_query($query_1) or die (mysql_error());
$row = mysql_fetch_array($result_1);

$id = $row['id'];
$username = $row['username'];
$email = $row['email'];
$country = $row['country'];
$avatar = $row['avatar'];

// check if the user has messages in there inbox.../////////////////////////////////
$query_msg = "SELECT * FROM `pms` WHERE `reciever_id`='$id'";
$result_msg = mysql_query($query_msg) or die (mysql_error());
$rows = mysql_fetch_array($result_msg) or die (mysql_error());

$how_many = mysql_num_rows($result_msg);

$read = $rows['read_flag'];

if (mysql_num_rows($result_msg) > 0) {

echo '<a href="inbox.php"><font color="red">Inbox</font></a>&nbsp;&nbsp;|&nbsp;';

} elseif ($read == 'N') {

echo '<a href="inbox.php"><font color="blue">Inbox</font></a>&nbsp;&nbsp;|&nbsp;';

} else {

echo '<a href="inbox.php">Inbox</a>&nbsp;&nbsp;|&nbsp;';

}
?>

i know i need to loop all the messaages to see if they are read or not but not sure how to go about it here lol

any help/advice would be appreciatede

Cheers

Graham

PappaJohn
08-07-2007, 08:45 PM
Instead of:


$rows = mysql_fetch_array($result_msg) or die (mysql_error());

$how_many = mysql_num_rows($result_msg);

$read = $rows['read_flag'];

if (mysql_num_rows($result_msg) > 0) {

echo '<a href="inbox.php"><font color="red">Inbox</font></a>&nbsp;&nbsp;|&nbsp;';

} elseif ($read == 'N') {

echo '<a href="inbox.php"><font color="blue">Inbox</font></a>&nbsp;&nbsp;|&nbsp;';

} else {

echo '<a href="inbox.php">Inbox</a>&nbsp;&nbsp;|&nbsp;';

}


try


$how_many = mysql_num_rows($result_msg);

$box_color = "red";

while ($row = mysql_fetch_assoc($result_msg) or die (mysql_error())
{
if ( $row['read_flag'] == 'N')
{
$box_color = "blue";
}
}

echo '<a href="inbox.php"><font color="' . $box_color . '">Inbox</font></a>&nbsp;&nbsp;|&nbsp;';

graham23s
08-07-2007, 11:34 PM
That works perferct ,mate thanks for that:)

Graham



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum