graham23s Posted August 21, 2007 Share Posted August 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66021-changing-text-colour/ Share on other sites More sharing options...
samoht Posted August 21, 2007 Share Posted August 21, 2007 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?? Quote Link to comment https://forums.phpfreaks.com/topic/66021-changing-text-colour/#findComment-330164 Share on other sites More sharing options...
graham23s Posted August 21, 2007 Author Share Posted August 21, 2007 Hi Mate, the only thing is, if i put it inside the while loop it gererates the work "Inbox" X amount of times because its looping it. Graham Quote Link to comment https://forums.phpfreaks.com/topic/66021-changing-text-colour/#findComment-330170 Share on other sites More sharing options...
samoht Posted August 21, 2007 Share Posted August 21, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/66021-changing-text-colour/#findComment-330186 Share on other sites More sharing options...
Barand Posted August 21, 2007 Share Posted August 21, 2007 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/66021-changing-text-colour/#findComment-330191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.