Forum Moderators: coopster

Message Too Old, No Replies

Image Display Problem

         

neroag

3:54 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi Guys
Im trying to find a way of dispalaying an image with a double barelled name ie "My Picture.jpg", the name is stored in the MySQL database as "My Picture.jpg" & on echo'ing the var it displays "My Picture.jpg" but when i use echo "<img src=$picture width=129 height=160>, it displays nothing & on getting the properties of the image it only shows the "My" & not the "My Picture.jpg" can anyone help please.

Thank you

dcrombie

4:14 pm on Jul 27, 2005 (gmt 0)



This is what you have now, which isn't working:

<img src=My Picture.jpg width=129 height=160>

This is what you should have:

<img src="My Picture.jpg" width="129" height="160" alt="">

;)

RammsteinNicCage

4:20 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



If you hardcoded this instead of using html, then what you would have is:

<img src=My Picture.jpg width=129 height=160>

So, as far as the browser knows, the src is just My. You need to wrap the source in quotes so that it looks like this:

<img src="My Picture.jpg" width=129 height=160>

To do this with php, you have to escape the quotes so that the echo call isn't terminated too early

echo "<img src=\"".$picture"\" width=129 height=160>";

I believe that should work. I'm not sure, maybe someone else can confirm this, but I think it's better to not even use a space in an image name, is that right?

Jennifer<--types too slowly without having breakfast

neroag

4:23 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi Thanx for the reply

The image name needs to be called from a variable hence the
echo "<b><img src=$picture width=129 height=160>";
when adding the alt="" i just get a Parse error: parse error, unexpected '"'

thanx

RammsteinNicCage

4:25 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



The reason you get the parse error is because the quotation marks, ", need to be escaped.

Jennifer

neroag

4:32 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi RammsteinNicCage
Thank you also for your help

echo "<img src=\"".$picture"\" width=129 height=160>"; height=160>";
also returns an error using exactly as you have written returns
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'

Im sorry im a newbie at php

neroag

4:37 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



LOL no matter i figured where the problem was echo "<img src=\"".$picture"\" width=129 height=160>"; height=160>"; needed the , after "".$picture,

Thank you again for your help it works a dream

RammsteinNicCage

4:42 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



I'm sorry, my bad. Try this:

echo "<img src=\"".$picture."\" width=\"129\" height=\"160\" alt=\" \">";

I forgot the second concatenation (dot). What they do is join <img src=" to My Picture.jpg to " width="129" height="160" alt=" "> so you're left with <img src="My Picture.jpg" width="129" height="160" alt=" ">

Jennifer

neroag

4:44 pm on Jul 27, 2005 (gmt 0)

10+ Year Member



Thank you for the explination A Good lesson learnt today, than you again its appreciated