Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Look At This Code For Changes


d4funky1

Recommended Posts

Hi,

 

Can anyone see what i would need to change in this code to select a specific category id rather than a random one as suggested?

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$category_query = tep_db_query("select distinct categories_id from ". TABLE_PRODUCTS_TO_CATEGORIES );
$cids = array();
while ($categories = tep_db_fetch_array($category_query)) {
	array_push($cids, $categories["categories_id"]);
}
$cid = $cids[rand(0, count($cids) - 1)];

  // removed order by p.products_date_added desc
$new_products_query = tep_db_query(
	"select p.products_id, p.products_image, p.products_tax_class_id, " .
		"if(s.status, s.specials_new_products_price, p.products_price) as products_price " .
	"from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id " .
	", ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c " .
	"where p.products_id = p2c.products_id and products_status = '1' and p2c.categories_id = $cid " .
	"order by rand() limit " . MAX_DISPLAY_NEW_PRODUCTS);
 } else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by rand() limit " . MAX_DISPLAY_NEW_PRODUCTS);
 }

 

Any help would be greatly appreciated.

 

Many Thanks

D4

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...