View Single Post
  #11  
Old 01-05-2013, 10:28 PM
 
anandat anandat is offline
 

X-Adept
  
Join Date: Jan 2004
Posts: 914
 

Default Re: Manufacturer on Product List / Recommended

Quote:
Originally Posted by cherie
I recommend doing a single query rather than a separate query for each product. For example (untested):

PHP Code:
$mids = array();
foreach (
$products as $p)
  
$mids[] = $p['manufacturerid'];
if (!empty(
$mids)) {
  
$manufacturers func_query_hash("SELECT manufacturerid,manufacturer FROM $sql_tbl[manufacturers] WHERE manufacturerid IN(".implode(',',$mids).")",'manufacturerid',FALSE,TRUE);
  foreach (
$products as $k=>$p)
    
$products[$k]['manufacturer'] = $manufacturers[$p['manufacturerid']];

I'd rather loop through products twice and do a single query than a single loop with multiple queries.

Hi Cherie
Thanks a lot your code works fine on all the pages for 4.5.4 i.e. on products.php, search.php & featured_products.php

Can you please explain me what is the advantage of your code ? I mean it will load the page fast or will use mysql more efficiently ?

Note: any body using this code just make sure that you do not keep any extra space on any line or you may get php error warning at admin/logs.php
__________________
X-Cart: 4.7.7 LIVE
Skin:Ultra by xcartmods.co.uk
X-cart Modules: | ACR, Rich Google Search, Customer Testimonials | Cloud Search, | Websitecm: CDSEO (2.1.9)
---------------
Server: Linux
php: 5.3
mysql: 5.0.89
----------------
Reply With Quote