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
yoda69
Forum Newbie
Posts: 16 Joined: Wed Jun 20, 2007 10:21 am
Post
by yoda69 » Thu Jun 21, 2007 7:24 am
hi,
can someone please help me with this "if" statement. somewhere i'm making a mistake:
Code: Select all
<?php
$haypicture="<td width="68%"><img src=\"/GY/images/masters/<?php echo \"$picture\";?>" alt="" name="teacher_image" border="0" id="teacher_image\"/></td>";
if ($rows['picture_id'] == "")
{
echo "
<td width="68%">no picture available</td>";
}else{
echo "$haypicture";
}
?>
Thanks guys,
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 21, 2007 7:29 am
Extra escaping is required of your double quotes. Note the highlighted code in your post for notable locations.
harsha
Forum Contributor
Posts: 103 Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India
Post
by harsha » Thu Jun 21, 2007 10:54 am
Code: Select all
<?php
$haypicture="<td width=\"68%\">".
"<img src=\"/GY/images/masters/{$picture} alt=\"\" name=\"teacher_image\" border=\"0\" id=\"teacher_image\"/></td>";
if ($rows['picture_id'] == "")
{
echo "<td width=\"68%\">no picture available</td>";
}else{
echo "{$haypicture}";
}
?>
I guess this will work fine;
when ever you want to embed a variable inside echo use flower braces;
ex:
Code: Select all
$name="Adam";
echo "Name: {$name}";
will print
Name: Adam
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 21, 2007 11:18 am
Code: Select all
<?php
$haypicture = '<td width="68%"><img src="/GY/images/masters/' . $picture .'" alt="" name="teacher_image" border="0" id="teacher_image" /></td>';
if ($rows['picture_id'] == "")
{
echo '
<td width="68%">no picture available</td>';
} else {
echo $haypicture;
}
?>
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jun 21, 2007 11:21 am
This might actually be better:
Code: Select all
<?php
echo '<td width="68%">';
if ($rows['picture_id'] == '') {
echo 'No picture available';
} else {
echo '<img src="/GY/images/masters/' . $picture .'" alt="" name="teacher_image" border="0" id="teacher_image" />';
}
echo '</td>';
?>