Page 1 of 1
If + echo issue
Posted: Thu Jun 21, 2007 7:24 am
by yoda69
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,
Posted: Thu Jun 21, 2007 7:29 am
by feyd
Extra escaping is required of your double quotes. Note the highlighted code in your post for notable locations.

Posted: Thu Jun 21, 2007 10:54 am
by harsha
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
Posted: Thu Jun 21, 2007 11:18 am
by RobertGonzalez
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;
}
?>
Posted: Thu Jun 21, 2007 11:21 am
by RobertGonzalez
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>';
?>