Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Only display the 2nd product image on product_info.php


alix32

Recommended Posts

Hello all! I'm in the process of re-building my very old 2.2 site on 2.3.4. On the product_info page, my main image is displaying nicely along with its sub-images below. What I'd like to do now is copy over the image display code further down the page in a product description section. In that section, I'd like to display 2nd image of the product only if there are more than 1 image linked to that product, else I'd like to display the main image again.

I've been scratching my head on this one but my poor knowledge of PHP has brought me to posting my question to this forum.

So here's the code I have to display my product images. The main image appears in large (width of 410) and the next images appear smaller (width of 102) below the main image

 

<?php
    if (tep_not_null($product_info['products_image'])) {
      $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");

      if (tep_db_num_rows($pi_query) > 0) {
?>

    <div id="piGal" style="float: left;">
      <nav>
	  <ul>

<?php
        $pi_counter = 0;
        while ($pi = tep_db_fetch_array($pi_query)) {
          $pi_counter++;

       $pi_entry = '        <li ' . ($pi_counter != 1 ? 'style="float:left;" class="imgthumbHover"' : '') . '><a href="';   
        
          if (tep_not_null($pi['htmlcontent'])) {
            $pi_entry .= '#piGalimg_' . $pi_counter;
          } else {
            $pi_entry .= tep_href_link(DIR_WS_IMAGES . $pi['image'], '', 'NONSSL', false);
          }
  if ($pi_counter == 1) {$piwidth = '410'; $piheight = ''; } else { $piwidth = '102'; $piheight = '200'; }
 $pi_entry .= '"rel="zoombox[vacances]">' . tep_image(DIR_WS_IMAGES . $pi['image'], $products_name, $piwidth, null) . '</a>';      
        
          if (tep_not_null($pi['htmlcontent'])) {
            $pi_entry .= '<div style="display: none;"><div id="piGalimg_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div></div>';
          }

          $pi_entry .= '</li>';

          echo $pi_entry;
        }
?>

      </ul>
	  </nav>
    </div>



<?php
      } else {
?>

    <div id="piGal" style="float: left;">
      <?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image'], '', 'NONSSL', false) . '"rel="zoombox[vacances]">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</a>'; ?>
    </div>

<?php
      }
?>

I understand that code will display my main image wider and above my sub-images if the product has more than 1 image, else it just displays the only image linked to that product.

But how could I change this code so that only the 2nd image displays if the product has more than 1 image, else display the only image linked to that product?

Hope that makes sense and someone knowledgeable is willing to take a few mns to help me out,

Thanks!

Link to comment
Share on other sites

Of course the sort_order! That worked perfectly thanks JcMagpie! 

<?php 
      if (tep_db_num_rows($pi_query) > 1) {
	  $pi_query = tep_db_query("select image from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' and sort_order=2");
?>

 

Edited by alix32
Link to comment
Share on other sites

When you say you're "re-building my very old 2.2 site on 2.3.4", I hope you mean the very latest osC, 2.3.4.1BS Edge/CE/Frozen. It gives you PHP 7.1 compatibility (a few fixes needed for 7.2), responsive design (mobile friendly), and a number of new features. Please don't use the official "latest" offering of 2.3.4.1, as it's years out of date.

Link to comment
Share on other sites

Uhm well Mr Phil...I hear you. Right now I'm re-building the site on 2.3.4.1 as quickly as possible. I gave the BS Edge version a shot but couldn't get my head round it. Right now I just need to get the site running on PHP 5.6 at least before my host provider turns the lights off as I'm still running on PHP 4 + it's not compatible with TLS1.2.

2.3.4.1 was the fastest option for me to be back in business. And then I'll indulge into the BS version.

Link to comment
Share on other sites

OK, Alix. At least you're aware of the situation, and plan to seriously look into the BS version. Actually, I can't even guarantee that the official 2.3.4.1 won't give you trouble with PHP 5.6 -- I don't think it was ever updated that far, so don't be surprised if something breaks. Good luck with your upgrading!

Link to comment
Share on other sites

When you say "the second image", do you mean the First Large Image?

#1 - thumbnail
#2 - first large image
#3 - second large image
etc

If this is the case (ie just show the first large image)..simply set "Thumbnail Layout" to 1.   Not more, not less... just "1".

 

Edit: 
Or don't. 
Just read rest of thread. 
You aren't using an up to date version of osCommerce, so that wont work. 
Here is code (still assuming you want the first large image):

tep_db_query("select image from products_images where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order limit 1");

 

Edited by burt
old version
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...