L Posted July 12, 2007 Share Posted July 12, 2007 Hello, My objective is to mark pms by have a blue picture, and a gray picture show. The blue mean its new ans the gray means it's already been read. Right now I have the pms in the inbox display by a while loop...but i want the picture to change if `new` in the `pm` table is either "yes" or "no". Here is my first attempt at this. $ipm = $view['new']; if ($ipm == Yes) { echo "<tr><td><img src=\"images/newpm.gif\" alt=\"\" /></td><td><a href=\"pmview.php?id=".$view['id']."\">".stripslashes(stripslashes($view['subject']))."</a></td><td><a href=\"account.php?user=".$user."\">".$user."</a></td><td>".$view['time_sent']."</td><td><a href=\"inbox.php?del=".$view['id']."\">Delete</a></td></tr>"; } else { echo "<tr><td><img src=\"images/oldpm.gif\" alt=\"\" /></td><td><a href=\"pmview.php?id=".$view['id']."\">".stripslashes(stripslashes($view['subject']))."</a></td><td><a href=\"account.php?user=".$user."\">".$user."</a></td><td>".$view['time_sent']."</td><td><a href=\"inbox.php?del=".$view['id']."\">Delete</a></td></tr>"; } it has a fetch array(where the $view[''] is coming from) and a if else statement...this all works except when a new message comes in....when a new message comes in the code read yes for that one pm for the rest, and then all the pms get the blue pic(meaning unread). How can i modify the above so I can have the image change to wheater the `new` colum is "Yes" or "No"? Thank you for your time; ~L Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 12, 2007 Share Posted July 12, 2007 make sure you reintalize the variable inside the while loop after you set it this is an example using a loop in loop <?php $i = 0 ; //Outter count $j = 0; //Inner count echo "<table>"; while ($i <50){ echo "<tr>"; while($j <10){ echo "<td>".$j."</td>"; $j++; } echo "</tr>"; $i++; } //The above version will not echo out beyond row 1 because $j is equal to 10 so this is what is needed $i = 0 ; //Outter count $j = 0; //Inner count echo "<table>"; while ($i <50){ $j = 0; //Resets $j for inner count echo "<tr>"; while($j <10){ echo "<td>".$j."</td>"; $j++; } echo "</tr>"; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
L Posted July 12, 2007 Author Share Posted July 12, 2007 yah..that seems to check out, but the weird thing is that when I look into my database the `new` column is now all "yes"...This makes no sense to me because I only update the `new` column when a user clicks on a pm...and that updates it to "no". Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 12, 2007 Share Posted July 12, 2007 You should use a bool type variable if it only has 2 options instead of a yes no varchar. It speeds up your table and it is better programing structure Quote Link to comment Share on other sites More sharing options...
L Posted July 12, 2007 Author Share Posted July 12, 2007 do you have a link where i can read up on bool type variables? google isn't doing me any good. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 12, 2007 Share Posted July 12, 2007 BOOL is really a psedo type for tinyint(1) but basically use it like an on off switch <?php if($row['messagestatus'] !=0){ //Its a new message} else{ //its old } ?> Quote Link to comment Share on other sites More sharing options...
L Posted July 12, 2007 Author Share Posted July 12, 2007 sorry if im making a simple mistake but it's not working.... set the `new` column to default 1(meaning new)...but when i send a new message it becomes zero, even though i only have one update query that could change it..and that's in the viewpm page...but im in the inbox and by default these messags should by blue, and the database should have values of 1, but they have 0....here's the code, UPDATE QUERY on VIEWPM mysql_query("UPDATE `PMs` SET `new`='0' WHERE `id`='$id'") or die(mysql_error()); while statement for viewing all pms pertaining to ur id. $ipm = $view['new']; if ($ipm != 0) { echo "<tr><td><img src=\"images/newpm.gif\" alt=\"\" /></td><td><a href=\"pmview.php?id=".$view['id']."\">".stripslashes(stripslashes($view['subject']))."</a></td><td><a href=\"account.php?user=".$user."\">".$user."</a></td><td>".$view['time_sent']."</td><td><a href=\"inbox.php?del=".$view['id']."\">Delete</a></td></tr>"; } else { echo "<tr><td><img src=\"images/oldpm.gif\" alt=\"\" /></td><td><a href=\"pmview.php?id=".$view['id']."\">".stripslashes(stripslashes($view['subject']))."</a></td><td><a href=\"account.php?user=".$user."\">".$user."</a></td><td>".$view['time_sent']."</td><td><a href=\"inbox.php?del=".$view['id']."\">Delete</a></td></tr>"; } Quote Link to comment Share on other sites More sharing options...
L Posted July 12, 2007 Author Share Posted July 12, 2007 my last post wasn't being edited so i posted a new reply. But that's because when I send a new message, it chagnes all the values in the `new` column to 0...this is including the one that i edited from the database making the value 1. Quote Link to comment Share on other sites More sharing options...
L Posted July 12, 2007 Author Share Posted July 12, 2007 Wow...i found my mistake....i had the update query to mysql_query("UPDATE `myPMs` SET `New`='0'"); That was my prob, thanx for all ur patience and the new idea of using bool variables. Works like a charm Thank you for your time and effort; Topic SOLVED! L Quote Link to comment 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.