PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
sguy
Forum Commoner
Posts: 61 Joined: Sun Aug 10, 2003 2:44 am
Post
by sguy » Wed Aug 25, 2004 10:00 am
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.
scorphus
Forum Regular
Posts: 589 Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:
Post
by scorphus » Wed Aug 25, 2004 10:21 am
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
sguy
Forum Commoner
Posts: 61 Joined: Sun Aug 10, 2003 2:44 am
Post
by sguy » Wed Aug 25, 2004 10:26 am
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";
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 10:36 am
missing a double quote on the first line there..
scorphus
Forum Regular
Posts: 589 Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:
Post
by scorphus » Wed Aug 25, 2004 10:42 am
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
sguy
Forum Commoner
Posts: 61 Joined: Sun Aug 10, 2003 2:44 am
Post
by sguy » Wed Aug 25, 2004 12:04 pm
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...
scorphus
Forum Regular
Posts: 589 Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:
Post
by scorphus » Wed Aug 25, 2004 12:08 pm
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
sguy
Forum Commoner
Posts: 61 Joined: Sun Aug 10, 2003 2:44 am
Post
by sguy » Wed Aug 25, 2004 11:17 pm
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.
Lord Sauron
Forum Commoner
Posts: 85 Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL
Post
by Lord Sauron » Thu Aug 26, 2004 1:00 am
What is the result of
print_r($number_of_array);
?
sguy
Forum Commoner
Posts: 61 Joined: Sun Aug 10, 2003 2:44 am
Post
by sguy » Thu Aug 26, 2004 1:30 am
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";