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

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.