alix32 Posted October 23, 2018 Share Posted October 23, 2018 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! Quote Link to comment Share on other sites More sharing options...
♥JcMagpie Posted October 23, 2018 Share Posted October 23, 2018 The images are all in one table so you will need to sort by product_id and some other id such as sort order, something like this, $sql = "SELECT id, products_id, sort_order, image FROM products_images WHERE products_id='29' AND sort_order='2'"; alix32 1 Quote Link to comment Share on other sites More sharing options...
alix32 Posted October 23, 2018 Author Share Posted October 23, 2018 (edited) 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 October 23, 2018 by alix32 Quote Link to comment Share on other sites More sharing options...
MrPhil Posted October 23, 2018 Share Posted October 23, 2018 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. Quote Link to comment Share on other sites More sharing options...
alix32 Posted October 24, 2018 Author Share Posted October 24, 2018 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. Quote Link to comment Share on other sites More sharing options...
MrPhil Posted October 24, 2018 Share Posted October 24, 2018 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! Quote Link to comment Share on other sites More sharing options...
burt Posted October 24, 2018 Share Posted October 24, 2018 (edited) 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 October 24, 2018 by burt old version Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.