Hello and welcome to our community! Is this your first visit?
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
    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.


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

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

    but it does not work yet if I use


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

    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.

  2. #2
    Master Coder
    Join Date
    Feb 2011
    Your Monitor
    Thanked 614 Times in 600 Posts
    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.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.


Posting Permissions

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