X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Manufacturer on Product List / Recommended (https://forum.x-cart.com/showthread.php?t=61592)

anandat 01-05-2013 10:28 PM

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

cherie 01-06-2013 09:06 AM

Re: Manufacturer on Product List / Recommended
 
The thing that affects your site's performance the most is your database. You should always limit the number of database queries where possible.


All times are GMT -8. The time now is 06:11 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.