Jump to content

Changing text colour


graham23s

Recommended Posts

Hi Guys,

 

i had this script down but have modified it, somewhere along the way and can't see where, what i had was, if there were messages in the users inbox the word "Inbox" would go red, if there were unread messages in there the "Inbox" would go blue if there were no messages it would simple be black

 

code:

 

<td align="center" class="navigation"><a href="myaccount.php">My Account</a></td>
<?php
## some inbox magic #####################################################################
$query_user = "SELECT `id` FROM `membership` WHERE `username`='$member'";
$result_user = mysql_query($query_user) or die (mysql_error());
$pm = mysql_fetch_array($result_user) or die (mysql_error());
$pm_id = $pm['id'];
## now we have id #######################################################################
$query_pm = "SELECT * FROM `pms` WHERE `reciever_id`='$pm_id'";
$result_pm = mysql_query($query_pm) or die (mysql_error());
$any_pms = mysql_num_rows($result_pm);
## any messages #########################################################################

$box_color = "red"; 

## loop through the pms to see if any are unread ########################################

while ($row = mysql_fetch_assoc($result_pm)) { 

    if ($row['read_flag'] == 'N') { 
    
        $box_color = "blue"; 
    } 
} 

## pm color normal ######################################################################

echo '<td align="center" class="navigation"><a href="inbox.php"><font color="'.$box_color.'">Inbox</font></a></td>';      

if($any_pms == 0) {

  echo '<td align="center" class="navigation"><a href="inbox.php"><font color="'.$box_color.'">Inbox</font></a></td>';

} 
?>
<td align="center" class="navigation"><a href="search.php">Search</a></td>

 

can nayone see where i have went wronhg here.

 

thanks guys

 

Graham

 

Link to comment
Share on other sites

the <font> tag is depreciated so you might want to change to <span class="'.$box_color.'"> and then set $box_color = color:red (or whatever)

 

I think you may want to place your echo inside your while loop. Otherwise you just set the $box_color but never put it with the appropriate record??

 

Link to comment
Share on other sites

I thought you were displaying the unread message title as well as changing its color?

 

mysql_fetch_assoc() will return one record  - if you want to check the db to see if their are any unread messages - you dont need the loop - unless you want to count the number of unread (but I didn't see that in your code)

 

Is this simply a boolean question (are there unread? Yes/No) if yes $box_color = blue??

 

or is it more complex?

Link to comment
Share on other sites

I'd (pseudocode)

    set it 'black' as default

    if messages 

            if  any unread 
                set to blue
            else
                set to red
            end if
    end if

 

eg

<?php
$sql = "SELECT COUNT(*) as msgs, SUM(IF(p.read_flag='N',1,0)) as unread
        FROM membership m INNER JOIN pms p ON m.id = p.receiver_id
        WHERE m.username = '$member' ";
$res = mysql_query($sql);
list ($msgs, $unread) = mysql_fetch_row($res);
$box_color = 'black';
if ($msgs)
{
    $box_color = $unread ? 'blue' : 'red';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.