Page 1 of 1
statement inside array
Posted: Wed Aug 25, 2004 10:00 am
by sguy
Code: Select all
while ($number_of_array = mysql_fetch_array($query)) {
echo "<TD><a href=viewuser.php?name=$number_of_array[nickname] target=_blank>$number_of_array[nickname]</a></TD>\n";
echo "<TD>$number_of_array[gender]</TD>\n";
echo "<TD>$age</TD>\n";
echo "<TD>$number_of_array[location]</TD>\n";
echo "<TD>$number_of_array[country]</TD>\n";
}
can i put the if else statement or while loop behind:
<a href=viewuser.php?name=$number_of_array[nickname] target=_blank>$number_of_array[nickname]</a>
if the value is equal to 1, then echo a picture
something like the picture attached...
i've tried, but got error...
thanks.
Posted: Wed Aug 25, 2004 10:21 am
by scorphus
1 - What is the error message?
2 - What does that if statement you tried look like?
3 - You could try something like this:
Code: Select all
<?php
//...
if (!empty($number_of_array['picture'])) //[php_man]empty[/php_man]()
echo '<img src="' . $number_of_array['picture'] . '" width="XX" height="XX" />';
//...
?>
4 - Quote the array indices like I did above.
-- Scorphus
Posted: Wed Aug 25, 2004 10:26 am
by sguy
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\phpweb\members\all.php on line 120
Code: Select all
echo "<TD><a href=viewuser.php?name=$number_of_array[nickname] target=_blank>$number_of_array[nickname]</a>
mysql_select_db($database, $conn);
$result=mysql_query("select * from user_detail where nickname = '$nickname'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
"$number_of_array[image]";
if ($image == 1) {
echo"<img src="image/camera.gif">;
}
}
</TD>\n";
Posted: Wed Aug 25, 2004 10:36 am
by feyd
missing a double quote on the first line there..
Posted: Wed Aug 25, 2004 10:42 am
by scorphus
And also in the fourth from down to top. Corrections:
Code: Select all
echo "<TD><a href=viewuser.php?name=$number_of_array[nickname] target=_blank>$number_of_array[nickname]</a>";
mysql_select_db($database, $conn);
$result=mysql_query("select * from user_detail where nickname = '$nickname'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
//"$number_of_array[image]"; //???
if ($image == 1) {
echo"<img src="image/camera.gif">";
}
}
echo "</TD>\n";
- Where does $image (if ($image == 1)) come from?
- What do you mean by the line "$number_of_array[image]";
-- Scorphus
Posted: Wed Aug 25, 2004 12:04 pm
by sguy
in my table has 1 column named "image", default is 0.
when i upload the picture, the 0 will set to 1.
then check the value, if the value is equal to 1, then show the camera.gif
this is what i meaned...

Posted: Wed Aug 25, 2004 12:08 pm
by scorphus
Ahn, so I think it should be:
Code: Select all
echo "<TD><a href=viewuser.php?name=$number_of_array[nickname] target=_blank>$number_of_array[nickname]</a>";
mysql_select_db($database, $conn);
$result=mysql_query("select * from user_detail where nickname = '$nickname'") ;
$number_of_array = mysql_num_rows($result);
while ($number_of_array = mysql_fetch_array($result)){
if ($number_of_array['image'] == 1) {
echo"<img src="image/camera.gif">";
}
}
echo "</TD>\n";
-- Scorphus
Posted: Wed Aug 25, 2004 11:17 pm
by sguy
i've tried, it shows the camera.gif in every nickname although the image is equal to 0, then the other value of the column is empty.
Posted: Thu Aug 26, 2004 1:00 am
by Lord Sauron
What is the result of
print_r($number_of_array);
?
Posted: Thu Aug 26, 2004 1:30 am
by sguy
i'm constantly overwriting the variable names, tried many times...
now works oredi...
thanks u all guys...
Code: Select all
$res = mysql_query("SELECT * FROM user_detail");
if(mysql_num_rows($res) > 0) {
while($row = mysql_fetch_array($res)) {
echo"<tr>";
echo '<td><a href="viewuser.php?name='.$row['nickname'].'" target="_blank">'.$row['nickname'].'</a>';
if($row['image'] == 1) {
echo '<img src="image/camera.gif" alt="camera" />';
}
echo '</td>'."\n";