Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default php variable within <img src>

    i'm working on some customizations to our tpl_product_info_display page. we have a custom field in our database called products_size. I'm trying to dynamically display an image based on the products size. i have created image files for each of the sizes our products come in. (18inch, 28inch, etc)

    the code that i've been pulling my hair out on works fine on my local test site via xampp. however, it does not work on the live site. (i'll explain "does not work" more below)

    here's the code.
    PHP Code:
    $inches $product_info->fields['products_size'] ;
    if (!empty(
    $product_info->fields['products_size'])) {
    print 
    '<img src="images/' $inches 'inch.gif">' ; } 
    when i run this on xampp, it displays the image file perfectly. when i run on a live site, and view the source code, there is a closing double quote appearing after the $inches variable. it should show up in the source as
    HTML Code:
    <img src="images/18inch.gif">
    but instead i see
    HTML Code:
    <img src="images/18"inch.gif />
    and obviously the image doesn't display.
    i've tried many variations of the code above. i've tried putting the $product_info->fields['product_size'] directly in the code instead of using the $inches variable.
    i've read a lot about variables not behaving properly when they're inside single quotes, so i tried changing all the containing quotes to double, and escaping the quotes that actually needed to appear.
    i even tested it by defining a dummy variable, $inches_test = '18', and inserted that in place of $inches in the example above. the variable passed properly and the image displayed fine. it stops working once i use the $product_info->fields['products_size'].. that seems to be what's throwing the extra double quotes into the mix.
    no matter what syntax i use, i keep coming back to it working fine locally, but not on my site.
    if someone could take a look and let me know where i'm breaking this code, i'd appreciate it.
    ps - not sure if it matters, but my local xampp is running php 5.2.4 and the live site runs 5.2.9
    Last edited by jc8125; 8 Jun 2009 at 04:20 PM.

  2. #2
    Join Date
    Mar 2004
    Posts
    688
    Plugin Contributions
    0

    Default Re: php variable within <img src>

    What exactly is the [FONT=Courier New]$product_info->fields['products_size'] is it 18"?[/FONT]
    [FONT=Courier New][/FONT]
    [FONT=Courier New]or just 18?[/FONT]

  3. #3
    Join Date
    Oct 2007
    Posts
    143
    Plugin Contributions
    0

    Default Re: php variable within <img src>

    hehe.. we have about 2,000 products, and 95% of them the sizes are listed as '18', '28', etc.. for some reason the last time someone uploaded with easy populate, they put 18" instead of 18. the category i was using for testing this new change just happened to fall in that 5%. i checked a different category, and saw they were displaying fine. came back here to update the thread, but you beat me to it. in retrospect, i can't believe i didn't check that. for some reason my brain was in "coding mode", and was only thinking of the double quotes as php symbols, not as the inch symbol.. if that makes any sense. anyway, i've fixed the product records and all is well. thanks for taking a look anyway..!

 

 

Similar Threads

  1. Replace product IMG with php code?
    By liderbug in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 18 Dec 2009, 11:03 PM
  2. img src not showing image
    By kiwi1066 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 17 Feb 2009, 12:15 PM
  3. Replies: 0
    Last Post: 15 Jan 2009, 03:48 PM
  4. additional img problem - can't see the original img thumb!
    By poosk in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 30 Aug 2007, 05:24 PM

Posting Permissions

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