Image path with php variable as height and width

I have a few module icons, and in the database the full path is placed in there and its called onto the website in its entirity.
It was working fine until i wanted to control the height and width through variables and then the icon no longer shows.

This is the image code and path as I have it in the database.


<img src="images/ModuleIcons/Colour/food.png" alt="FoodCheck Module - Certified" border="0" class="moduleIcon" height="<?= $icon_Height ?>" width="<?= $icon_Width ?>" />

Which worked fine with the following code below, until i wanted to control the height and width through php.


$icon_Height='57px';
$icon_Width='56px';

<a href="javascript:popUp('<? echo "standdata.php?srno=$q[Id_Stand]"; ?>','')" title="<?=$q['stand_Name']?>"><? echo $q['Nom_Stand']?></a>

But now the icon wont show at all.

What is the HTML output (perform a view-source and copy the img tag here) that is generated from your code?

Hi cpradio,

<a href=“javascript:popUp(‘standdata.php?srno=10’,‘’)” title=“Food Safety”><img src=“images/ModuleIcons/Colour/food.png” alt=“FoodCheck Module - Certified” border=“0” class=“moduleIcon” height=“<?= $icon_Height ?>” width=“<?= $icon_Width ?>” /></a>

Thats the HTML output…

Okay, so why isn’t it parsing the <?= $icon_Height ?> and <?= $icon_Wdith ?> tags? Do you have them within a PHP file?

Yep, strange isnt it…

They placed at the top of the page with the other variables.

<?
$icon_Height=“57px”;
$icon_Width=“56px”;
?>

http://devchecksafetyfirst.csf.dcmanaged.com/hotel.php?hotel_ID=246687

On the right side, where it says compliant with these standards should be the lone icon that should be showing which is the only one im trying it out on at the mo

Yes, but the PHP isn’t being parsed. I feel like something is missing here, are you pulling the img tag from an external source (including it, ajax, etc)?

No the full path:

<img src=“images/ModuleIcons/Colour/food.png” alt=“FoodCheck Module - Certified” border=“0” class=“moduleIcon” height=“<?= $icon_Height ?>” width=“<?= $icon_Width ?>” />

Is in the database under Nom_Stand…

Then on the page the variables are declared at the top:

$icon_Height=“57px”;
$icon_Width=“56px”;

Then this is the code in the HTML calling that img path.


<div id="hotel_Picture_Section_Right_Right">Compliant with these standards<br/>
<?
$y=mysql_query("select tbl_standards.Id_Stand, tbl_standards.Nom_Stand, tbl_standards.stand_Name FROM tbl_standards LEFT JOIN tbl_hotnstand ON (tbl_hotnstand.Id_Stand=tbl_standards.Id_Stand) WHERE tbl_hotnstand.Id_Hot=".$hotelID." AND (tbl_standards.Id_View='1') GROUP by tbl_standards.Nom_Stand");
while($q=mysql_fetch_assoc($y)){ ?>
<? if ($q['Id_Stand'] == '18' ) { ?>

<? } else { ?>
<a href="javascript:popUp('<? echo "standdata.php?srno=$q[Id_Stand]"; ?>','')" title="<?=$q['stand_Name']?>"><? echo $q['Nom_Stand']?></a>
<? } ?>
<? } ?>
</div>

Ah, I see. so the value from the database is

<img src="images/ModuleIcons/Colour/food.png" alt="FoodCheck Module - Certified" border="0" class="moduleIcon" height="<?= $icon_Height ?>" width="<?= $icon_Width ?>" />

That is why the variables are not being parsed. That would be a HUGE security risk if PHP parsed that data.

You’ll want to do a str_replace

$imageTag = '<img src="images/ModuleIcons/Colour/food.png" alt="FoodCheck Module - Certified" border="0" class="moduleIcon" height="<?= $icon_Height ?>" width="<?= $icon_Width ?>" />';
$imageTag = str_replace('<?= $icon_Height ?>', $iconHeight, $imageTag);
$imageTag = str_replace('<?= $icon_Width ?>', $iconWidth, $imageTag);

Oh right I see, so you cant do that can you?

Thanks cpradio, will use the str_replace as you say.

Will have to do it this way -


<?
$imageTag = $q['Nom_Stand'];
$imageTag = str_replace('<?= $icon_Height ?>', $icon_Height, $imageTag);
$imageTag = str_replace('<?= $icon_Width ?>', $icon_Width, $imageTag);
?>

<a href="javascript:popUp('<? echo "standdata.php?srno=$q[Id_Stand]"; ?>','')" title="<?=$q['stand_Name']?>"><?=$imageTag?></a>

Seems tohave worked out, thanks cpradio once again

Just validated your site and there are numerous errors which may be causing your problems:

http://validator.w3.org/check?uri=http%3A%2F%2Fdevchecksafetyfirst.csf.dcmanaged.com%2Fhotel.php%3Fhotel_ID%3D246687&charset=(detect+automatically)&doctype=Inline&group=0