[SOLVED] href and image source

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris100
Forum Newbie
Posts: 2
Joined: Mon Apr 04, 2005 6:53 pm

[SOLVED] href and image source

Post by chris100 »

I'm new to php and am trying to duplicate some html code in php.

This is an example of code that I have that works.

echo "<a href = \"$url\">\"aloe.jpg\"</a>\n";

I can create the $url from mysql data but I haven't been able to figure out how to create an <img src of "aloe.jpg". Insted the word "aloe.jpg" appears when I run the script.

I checked the php manual and and googled just about phrase I could think might get some results. No luck!

Any help would be very appreciated.

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

echo '<a href = "'.$url.'">'.$picname.'</a>\n';
or

Code: Select all

echo "<a href = \"$url\">$picname</a>\n";
That what you wanted?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

chris100 wrote: I can create the $url from mysql data but I haven't been able to figure out how to create an <img src of "aloe.jpg". Insted the word "aloe.jpg" appears when I run the script.

Thanks
that's because you are simply echoing out the image name itself instead of actually showing the image....

Code: Select all

echo "<a href = "$url">"aloe.jpg"</a>\n";
should actually be

Code: Select all

echo '<a href="'.$url.'"><img src="aloe.jpg"></a><br>';

*curses php tag*

Code: Select all

echo '<img src="'.$url.'aloe.jpg"></a><br>';
Last edited by infolock on Mon Apr 04, 2005 7:40 pm, edited 6 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

echo '<a href="' . $url . '"><img src="' . $pic . '" /></a>' . "\n";
:?:
chris100
Forum Newbie
Posts: 2
Joined: Mon Apr 04, 2005 6:53 pm

Post by chris100 »

Thanks so much guys, it works great. I'll keep on coding and will probably be back with more questions soon.

Thanks again
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

chris100 wrote: will probably be back with more questions soon.
I can't wait ;)
Post Reply