Jump to content

[SOLVED] if within a while loop


L

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/59584-solved-if-within-a-while-loop/
Share on other sites

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++;
}
?>

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>"; 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.