Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Nov 2008
    Posts
    45
    Plugin Contributions
    0

    Default PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display.php

    Not sure if this is the right forum for php questions, but I'm having trouble finding a PHP forum

    I'm trying to display the manufacturers image on the product info page which when clicked goes to their url to see all that manufacturers products

    My coding is in the following .php file:
    /includes/templates/mytemplate/templates/tpl_product_info_display.php The problem is that only the first manufacturers image is shown on all products, even those that belong to the second manufacturer. Can anyone spot what I have wrong please? (I've resorted to hardcoding the urls and images which is why I need an if statement, as I couldn't get it to work at all when trying to get the manufacturers url and image from the database, and since there are only two of us ...!)

    This is my problem coding:

    <?php

    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);

    If ($manufacturers_name = "Sandie Burchell") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=3"> <img src="/images/sandie_burchell.jpg"> </a>

    <?php
    } elseif ($manufacturers_name = "Sue Douglas") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=4"> <img src="/images/sue_douglas.jpg"> </a>
    <?php
    }
    ?>

    If I'm totally in the wrong forum for this question, could anyone recommend a good (preferably free!) PHP forum that would be able to help me please?

    Thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,870
    Plugin Contributions
    96

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by suedouglas View Post
    Not sure if this is the right forum for php questions, but I'm having trouble finding a PHP forum

    I'm trying to display the manufacturers image on the product info page which when clicked goes to their url to see all that manufacturers products

    My coding is in the following .php file:
    /includes/templates/mytemplate/templates/tpl_product_info_display.php The problem is that only the first manufacturers image is shown on all products, even those that belong to the second manufacturer. Can anyone spot what I have wrong please? (I've resorted to hardcoding the urls and images which is why I need an if statement, as I couldn't get it to work at all when trying to get the manufacturers url and image from the database, and since there are only two of us ...!)

    This is my problem coding:

    <?php

    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);

    If ($manufacturers_name = "Sandie Burchell") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=3"> <img src="/images/sandie_burchell.jpg"> </a>

    <?php
    } elseif ($manufacturers_name = "Sue Douglas") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=4"> <img src="/images/sue_douglas.jpg"> </a>
    <?php
    }
    ?>

    If I'm totally in the wrong forum for this question, could anyone recommend a good (preferably free!) PHP forum that would be able to help me please?

    Thanks!
    You've used assignment operators (single equal sign) instead of equality operations (double equal sign):
    Code:
    <?php
    
    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);
    
    If ($manufacturers_name == "Sandie Burchell") { 
    ?>
    <a href="index.php?main_page=index&manufacturers_id=3"> <img src="/images/sandie_burchell.jpg"> </a>	
    
    <?php
    } elseif ($manufacturers_name == "Sue Douglas")  {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=4"> <img src="/images/sue_douglas.jpg"> </a>	
    <?php
    } 
    ?>

  3. #3
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by lat9 View Post
    You've used assignment operators (single equal sign) instead of equality operations (double equal sign):
    The recommendation these days is to use a triple equals sign (===)

    Cheers
    RodG

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,870
    Plugin Contributions
    96

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by RodG View Post
    The recommendation these days is to use a triple equals sign (===)

    Cheers
    RodG
    Agreed, on new code; simply changing all == (equal to) to === (exactly equal to) in "legacy" code can have unwanted consequences.

  5. #5
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by lat9 View Post
    Agreed, on new code; simply changing all == (equal to) to === (exactly equal to) in "legacy" code can have unwanted consequences.
    Yes, I am aware that there is a subtle difference between == and ===

    Just curious, it a known fact about 'unwanted consequences' , or is it the same disclaimer that I probably should have made on the basis that it probably hasn't been tested in every possible case?

    Fact or not, I agree, it doesn't make sense take the risk of retroactively changing all legacy code due to the current recommendations.

    I do like the idea of making PHP a little more strict though, and for new code, the === is less likely to have unwanted consequences than the ==, and generally speaking, if I AM working on legacy code and come across the odd == I tend to automatically change it to the === and test that nothing got busted as a result (so far, I haven't busted anything by doing this), hence my curiosity as to whether the 'unwanted consequences' are real, or just something that is theoretically possible.

    "I don't know either" is a perfectly acceptable answer. :-)

    Cheers
    Rod.

  6. #6
    Join Date
    Nov 2008
    Posts
    45
    Plugin Contributions
    0

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Thanks so much everyone who replied! The === sign worked fine! I've spent about 5 days on this one piece of coding so I'm delighted I now know what the problem is! I was under the misconception that the == meant not equal to, even though I had seen coding with the != as well which I know for sure is not equal to, because I do write SQL. This was most definitely my problem with trying to get the data from the database too!!
    Thanks so much for your help, it's much appreciated!

  7. #7
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by RodG View Post
    Yes, I am aware that there is a subtle difference between == and ===

    Just curious, it a known fact about 'unwanted consequences' , or is it the same disclaimer that I probably should have made on the basis that it probably hasn't been tested in every possible case?

    Fact or not, I agree, it doesn't make sense take the risk of retroactively changing all legacy code due to the current recommendations.

    I do like the idea of making PHP a little more strict though, and for new code, the === is less likely to have unwanted consequences than the ==, and generally speaking, if I AM working on legacy code and come across the odd == I tend to automatically change it to the === and test that nothing got busted as a result (so far, I haven't busted anything by doing this), hence my curiosity as to whether the 'unwanted consequences' are real, or just something that is theoretically possible.

    "I don't know either" is a perfectly acceptable answer. :-)

    Cheers
    Rod.
    Outside of ZC I was programming some PHP to provide some information. During the initial coding I had used == for all such verification of equalities. I then chose to use === in all such cases by replacement of the two with the three. Problems followed. The most basic example of where such a problem is likely to occur is if the false statement is used to capture situations where the value is 0 or false... Certainly with a newer perspective one could evaluate using both criteria ored together, but under the "old" thought there was no need...

    There may be other examples, but that is one that I have seen/experienced.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,870
    Plugin Contributions
    96

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by RodG View Post
    Yes, I am aware that there is a subtle difference between == and ===

    Just curious, it a known fact about 'unwanted consequences' , or is it the same disclaimer that I probably should have made on the basis that it probably hasn't been tested in every possible case?

    Fact or not, I agree, it doesn't make sense take the risk of retroactively changing all legacy code due to the current recommendations.

    I do like the idea of making PHP a little more strict though, and for new code, the === is less likely to have unwanted consequences than the ==, and generally speaking, if I AM working on legacy code and come across the odd == I tend to automatically change it to the === and test that nothing got busted as a result (so far, I haven't busted anything by doing this), hence my curiosity as to whether the 'unwanted consequences' are real, or just something that is theoretically possible.

    "I don't know either" is a perfectly acceptable answer. :-)

    Cheers
    Rod.
    As mc12345678 replied, there are places within Zen Cart (and especially the plugins!) where configuration values are checked as
    Code:
    if (CONFIGURATION_VALUE_CONSTANT == 0) {
    }
    which works just fine. The construct
    Code:
    if (CONFIGURATION_VALUE_CONSTANT === 0) {
    }
    will never evaluate to true, since configuration constants are strings, requiring the exactly-equal-to code to be formatted as
    Code:
    if (CONFIGURATION_VALUE_CONSTANT === '0') {
    }
    Last edited by lat9; 13 May 2015 at 09:10 PM. Reason: Corrected misspelling

  9. #9
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    Quote Originally Posted by suedouglas View Post
    Not sure if this is the right forum for php questions, but I'm having trouble finding a PHP forum

    I'm trying to display the manufacturers image on the product info page which when clicked goes to their url to see all that manufacturers products

    My coding is in the following .php file:
    /includes/templates/mytemplate/templates/tpl_product_info_display.php The problem is that only the first manufacturers image is shown on all products, even those that belong to the second manufacturer. Can anyone spot what I have wrong please? (I've resorted to hardcoding the urls and images which is why I need an if statement, as I couldn't get it to work at all when trying to get the manufacturers url and image from the database, and since there are only two of us ...!)

    This is my problem coding:

    <?php

    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);

    If ($manufacturers_name = "Sandie Burchell") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=3"> <img src="/images/sandie_burchell.jpg"> </a>

    <?php
    } elseif ($manufacturers_name = "Sue Douglas") {
    ?>
    <a href="index.php?main_page=index&manufacturers_id=4"> <img src="/images/sue_douglas.jpg"> </a>
    <?php
    }
    ?>

    If I'm totally in the wrong forum for this question, could anyone recommend a good (preferably free!) PHP forum that would be able to help me please?

    Thanks!
    Quote Originally Posted by suedouglas View Post
    Thanks so much everyone who replied! The === sign worked fine! I've spent about 5 days on this one piece of coding so I'm delighted I now know what the problem is! I was under the misconception that the == meant not equal to, even though I had seen coding with the != as well which I know for sure is not equal to, because I do write SQL. This was most definitely my problem with trying to get the data from the database too!!
    Thanks so much for your help, it's much appreciated!
    As to a possibly more rounded approach to the solution now that it is more clearly represented than in a previous related thread:

    Code:
    <?php
    
    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);
    
    ?>
    <a href="<?php echo zen_href_link(FILENAME_DEFAULT, "manufacturers_id=" . zen_get_products_manufacturers_id($product_info->fields['products_id']), $request_type); ?>"><img src="<?php echo zen_get_manufacturers_image($product_info->fields['products_id']); ?>"></a>
    This is untested, so may have some error(s)...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: PHP question on /includes/templates/mytemplate/templates/tpl_product_info_display

    In my above recoding I forgot that there is a function also to provide the image html through ZC as well... So the above falls short of a truly Zen response.

    zen_image( $src, [ $alt = ''], [ $width = ''], [ $height = ''], [ $parameters = ''])
    Where $src would be everything provided above at and after the
    Code:
    <img src=
    section related to the image....

    Quote Originally Posted by mc12345678 View Post
    As to a possibly more rounded approach to the solution now that it is more clearly represented than in a previous related thread:

    Code:
    <?php
    
    $manufacturers_name = zen_get_products_manufacturers_name($product_info->fields['products_id']);
    
    ?>
    <a href="<?php echo zen_href_link(FILENAME_DEFAULT, "manufacturers_id=" . zen_get_products_manufacturers_id($product_info->fields['products_id']), $request_type); ?>"><?php echo zen_image(zen_get_manufacturers_image($product_info->fields['products_id'])); ?></a>
    This is untested, so may have some error(s)...
    Last edited by mc12345678; 13 May 2015 at 09:36 PM. Reason: forgot a closing parentheses
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Question regarding $manufacturers_id in tpl_product_info_display.php
    By shirster in forum General Questions
    Replies: 2
    Last Post: 9 Jul 2013, 04:59 AM
  2. Problems with includes/config.php and admin/includes.php
    By Scott83 in forum Basic Configuration
    Replies: 2
    Last Post: 23 Oct 2009, 07:09 PM
  3. PhP question about a line of code in includes/classes/order.php
    By dbrewster in forum Managing Customers and Orders
    Replies: 12
    Last Post: 1 Feb 2007, 03:30 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