Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2013, 03:07 PM   PM User | #1
chriswilby
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
chriswilby is an unknown quantity at this point
Unhappy Problem with displaying images using variable in php

I am using this syntax in php to display a picture.

$pict="photoids/1368.jpg";

$picture='<img src="$pict" >';

then
echo '<td>' . $picture . '</td>';

but it does not work yet if I use

$pict="photoids/1368.jpg";

$picture='<img src="photoids/1368.jpg" >';

then
echo '<td>' . $picture . '</td>';

the picture is displayed.
But I want to use different values of the image number to display different pictures in the table.

Can you help me sort out the above code used in php.
thankyon
chriswilby is offline   Reply With Quote
Old 01-20-2013, 03:30 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
It's our use of quotes and variables inside them.

To put it simply, you can't use a $Variable inside 'single quotes' and expect PHP to replace it. You can only use a $Variable inside "double quotes". If you need to use " inside double quotes then you need to escape it like this:

$picture = "<img src=\"$pict\" >";

The \ tells PHP that the character following should be ignored and treated the same as the rest.

See the link in my signatures about quotes for a more indepth explanation.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:54 PM.


Advertisement
Log in to turn off these ads.