Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,339
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •