PDA

View Full Version : image


edbr
11-14-2007, 10:07 AM
I want to add an image to a results set
<img src="images/ $myrow["title"] /1.jpg" alt=" $myrow["title"]" width="100" height="75 />


$myrow["title"] being the dynamic link.Is this possible?? elsewhere in the set i use

print "<div class= \"cell\">";
echo $myrow["title"] ;
print "</div>";
but using \" where i thought i wrong or i am using it wrongly which is more likely.

lux
11-16-2007, 02:37 PM
if the image you wish to use is the same for all rows then you can do this:


print "<div class= \"cell\">";
echo $myrow["title"] ;
echo "<img src=\"images/filename.jpg\" />";
print "</div>";


if the image is dynamic then you need to have a column in your database which holds the path and name of the file. then in you php you write:


print "<div class= \"cell\">";
echo $myrow["title"] ;
echo "<img src=\"".$myrow['path_to_image']."\" />";
print "</div>";


'path_to_image' is the name of the database column which holds the path to the image.
[/php]

hope this helps

edbr
11-19-2007, 02:04 AM
thanks I did it already , clearer head in the morning! echo "<a href=\"villa.php?villaID=$d\">";
echo " <img src=\"images/" ;
echo $d ;
echo " /1.jpg \" width=\"100\" height=\"75\"/>";
echo "Click for details</a>";

lux
11-19-2007, 12:22 PM
cool

just to note you can echo all of this from one line:


echo "<a href=\"villa.php?villaID=$d\"><img src=\"images/$d/1.jpg \" width=\"100\" height=\"75\"/>Click for details</a>";

davidj
11-19-2007, 12:44 PM
nice point lux

personaly i would assign the HTML to a var and echo the var

or if you are inside HTML and are displaying conditional data then i tend to do the following...

notice how i close the PHP tag after the open brace to allow normal HTML then terminate the brace within its own PHP tag.

<?php if(condition == true){ ?>

<a href="villa.php?villaID=<?php echo $d ?>"><img src="images/<?php echo $d ?>/1.jpg " width="100" height="75"/>Click for details</a>

<?php } ?>


notice there is no HTML literal back-slash for any quotes when doing it this way

lux
11-19-2007, 01:06 PM
davidj do you ever use <?=$var ?> to echo a var or do you think this should be avoided?

davidj
11-19-2007, 01:31 PM
never used it

prefer familiar syntax then i don't have to work out what the hell is going on

if any method works for you then use it but i advise don't mix em up as thats a one way ticket to confusion city

lux
11-19-2007, 01:35 PM
haha fair enough

edbr
11-21-2007, 12:50 AM
thanks . Having spat out the DW dummy I am still getting to grips with this . making it work is one thing I want to tidy up later if I can. It a bit of a mess at present. Old dog new tricks etc etc