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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Location
    Northumberland UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <?PHP echo etc displaying but don't want it!

    Hi

    I want to be able to pick up the variable from the switch/case statements and use it within the echo text (html) of the case.

    When I view the source code of the page that that holds the code below, the $id is replaced with the variable (great) but it also shows the rest of the text <?php echo....... The variable that is picked up is also the name of the .jpg image and I would like the script to populate this automatically for all the instances where this occurs. Is it possible or am I hoping for too much?
    Code:
    <img class='prodimage' src='../images/<?php echo \"$id\" ; ?>.jpg'>
    Many thanks

    Andrew

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    So... are we viewing the HTML markup here or the PHP source? If / when you post PHP code, please use the PHP tags.

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    356
    Thanks
    19
    Thanked 2 Times in 2 Posts
    PHP Code:
    <img class='prodimage' src='../images/<?php echo $id?>.jpg'>
    Make sure this is in a file for .php (html will not run php codes properly)
    In a normal .php page this will work just perfectly.

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    25
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Like sitNsmile showed, you do not need quotations around a variable so instead of what you had:
    <?php echo \"$id\"; ?>

    You would use:
    <?php echo $id; ?>

    -Sam

  • #5
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    Quote Originally Posted by Ipssissimus View Post
    Hi

    I want to be able to pick up the variable from the switch/case statements and use it within the echo text (html) of the case.

    When I view the source code of the page that that holds the code below, the $id is replaced with the variable (great) but it also shows the rest of the text <?php echo....... The variable that is picked up is also the name of the .jpg image and I would like the script to populate this automatically for all the instances where this occurs. Is it possible or am I hoping for too much?
    Code:
    <img class='prodimage' src='../images/<?php echo \"$id\" ; ?>.jpg'>
    Many thanks

    Andrew

    If "<?php <value of $id; ?>" is being output then there is something weird going on.

    <?php just tells the parser when there is PHP to process ~ it should never be returned to the browser unless explicitly said so.

    Normally if tags are output, PHP isn't enabled, but you said the variable gets processed implying PHP is.

    Post this case statement as well.

    as for replacing any instance of the variable...thats what variables do. Replace any instance with the value. So i think there is some confusion here.

    post the whole code


  •  

    Posting Permissions

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