PDA

View Full Version : <img src=variable> ?


mat
09-04-2002, 12:32 AM
I am trying to output a variable into an <img tag and add a string onto the end,

So the variable is called $pic and has the value = images/rt1
I want to add "_small.jpg" onto that and put in an image source

This is my code:

<?php

mysql_connect('localhost', 'mine', 'mine');
mysql_select_db('mine');

$sql = "SELECT * FROM pots";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)){

$potName = $row['potName'];
$pic = $row['image'];
$ID = $row['potID'];

echo "name $potName<br>";

echo "<A HREF='detail.php?ID=$ID' target='popup' onClick='window.open('detail.php?ID=$ID','popup','width=330,height=430') return false'><img src="'$pic'_small.jpg"></a>";

}
?>



You can see the image is supposed to link to a pop up (big version)

Obviously this is wrong, i have tried all the different ways i can think of and i still get an error.

How can i do this?

mat,

michelle
09-04-2002, 12:48 AM
use this:



<img src="$pic.'_small.jpg'">

mordred
09-04-2002, 02:32 AM
$pic = $row['image'];
echo "<img src='{$pic}_small.jpg'></a>";

mat
09-04-2002, 02:33 AM
I'm getting the following error :(

Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in ..... on line 19

the only thing that has changed in the previoulsy posted code is the <img_src="$pic.'_small.jpg'"> bit as you suggested.


mat,

firepages
09-04-2002, 02:55 AM
......<img src=\"$pic"."_small.jpg\"></a>";

OR the cleaner method that Mordred suggests...

.....<img src=\"{$pic}_small.jpg\"></a>";

but you still have to escape those '\"' extra quotes

michelle
09-04-2002, 03:10 AM
Oh I'm sorry mat, I've overlooked that you use echo. firepages is the one.

mat
09-04-2002, 04:02 AM
:o thats quite alright, thanks. Working nicely now