Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Php Syntax Help - Custom Fields Switch

    I have some custom fields in my product info templates in my store. I want to create some switches so that if there is no data in the sql, the code disappears on the catalog side.

    This is what I have. It correctly comments out the code if there is no data in the sql BUT it is not displaying the sql data if there is data.

    Code:
    <?php $product_info = $db->Execute("select jewel_ring_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)zen_db_prepare_input($_GET['products_id']) . "'");
    if ($product_info->fields['jewel_ring_weight'] > 0) {
      echo '<br />';
      echo '<tr class="prodSpecItem2 prodS"><td class="prodSpec2">Weight - Band (g):</td><td>' . ($product_info->fields['jewel_band_weight'] ) . '</td></tr>';
    }
    ?>
    This is the code it is not displaying:

    <td>' . ($product_info->fields['jewel_band_weight'] ) . '</td>

    Is this the correct way to extract the data from the database? If not what am I doing wrong?

    Thanks for helping a novice.

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: Php Syntax Help - Custom Fields Switch

    I am not a very adept coder but I recall that the mysql call would be "get"
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Re: Php Syntax Help - Custom Fields Switch

    Thanks for the reply, but that didn't work. I know I'm close, but not quite there.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Php Syntax Help - Custom Fields Switch

    $product_info is used on the product_info page for the select already ...

    You really would do better to use your own variable for this and not the one running the page ...

    Also, in the where statement use:
    PHP Code:
    where products_id '" . (int)$_GET['products_id'] . "'"); 
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Re: Php Syntax Help - Custom Fields Switch

    Thanks, Ajeh. I am close, I believe. I incorporated your feedback.

    I changed $product_info to $product_band and I changed the where statement to the one you suggested.
    Code:
    <?php
    $product_band = $db->Execute("select jewel_ring_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$_GET['products_id'] . "'");
    if ($product_band->fields['jewel_ring_weight'] > 0) {
      echo '<br />';
      echo '<tr class="prodSpecItem2 prodS"><td class="prodSpec2">Weight - Band (g):</td><td>' . ($product_band->fields['jewel_band_weight'] ) . '</td></tr>';
    }
    ?>
    But the actual sql data still isn't pulled yet and the code does not disappear if the sql data is blank.

    To see whats going on see here, scroll to the bottom of the product details table below the main image. It says 'Weight - band' but the cell next to this is empty.

    Thanks in advance.
    Last edited by voltage; 22 Jul 2006 at 04:07 PM.

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Php Syntax Help - Custom Fields Switch

    Bet if you were to echo: $product_band->fields['jewel_ring_weight']

    Instead of echoing: $product_band->fields['jewel_band_weight']

    You'd see more ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Re: Php Syntax Help - Custom Fields Switch

    Doh! Now that is just embarrassing! Geez . . . Thanks Ajeh for lending your expertise. It appears to work now.

  8. #8
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Re: Php Syntax Help - Custom Fields Switch

    I know i am pressing my luck with all of these questions but how do I do a switch if sql data is text and not numeric? The > 0 doesn't seem to have any effect.

  9. #9
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    1,410
    Plugin Contributions
    1

    Default Re: Php Syntax Help - Custom Fields Switch

    Answer change: > 0 to > ''

 

 

Similar Threads

  1. Parse error: syntax error, unexpected '{' in my custom php code
    By claudiapsp in forum General Questions
    Replies: 2
    Last Post: 27 Mar 2014, 03:53 PM
  2. Help with PHP syntax on sidebox
    By sunflowertami in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 24 Aug 2008, 12:34 PM
  3. Help with PHP syntax please?
    By sunflowertami in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 17 Jun 2008, 11:48 AM
  4. PHP syntax help
    By KTNaturals in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 28 Feb 2007, 01:48 AM
  5. Easy PHP syntax question -- help please?
    By magicpants in forum General Questions
    Replies: 2
    Last Post: 17 Jan 2007, 02:31 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