Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help with if statement


Mighty Mike

Recommended Posts

Posted

Hi

 

I have modified my whats_new box to select a product from the same category that a customer is viewing or if not on a category page select anything...

 

if (isset($current_category_id) && ($current_category_id > 0)) {
 $random_product = tep_random_select("select p.products_id, p.products_image from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' AND p.products_id <> '131' AND p.products_id <> '134' AND p.products_id <> '135' AND products_date_available > '".$date_time_lag."' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by products_date_available desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
 $random_product = tep_random_select("select products_id, products_image from " . TABLE_PRODUCTS . " where products_status = '1' AND products_id <> '131' AND products_id <> '134' AND products_id <> '135' AND products_date_available > '".$date_time_lag."' order by products_date_available desc limit " . MAX_RANDOM_SELECT_NEW);
}

 

The old code used to be...

  if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

 

Now if no product was found it would not display the box but with my code it will still display the box but have nothing in it :( how do i adjust my statement so that if it finds no product in either query it does not display the box?

 

Any help appreciated

 

Thanks :thumbsup:

Posted
Hi

 

I have modified my whats_new box to select a product from the same category that a customer is viewing or if not on a category page select anything...

 

if (isset($current_category_id) && ($current_category_id > 0)) {
 $random_product = tep_random_select("select p.products_id, p.products_image from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' AND p.products_id <> '131' AND p.products_id <> '134' AND p.products_id <> '135' AND products_date_available > '".$date_time_lag."' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by products_date_available desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
 $random_product = tep_random_select("select products_id, products_image from " . TABLE_PRODUCTS . " where products_status = '1' AND products_id <> '131' AND products_id <> '134' AND products_id <> '135' AND products_date_available > '".$date_time_lag."' order by products_date_available desc limit " . MAX_RANDOM_SELECT_NEW);
}

 

The old code used to be...

  if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status = '1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

 

Now if no product was found it would not display the box but with my code it will still display the box but have nothing in it :( how do i adjust my statement so that if it finds no product in either query it does not display the box?

 

Any help appreciated

 

Thanks :thumbsup:

 

whether you display the box has nothing to do with the query but the code around it.

so in your case you check after that code with

 

if ($random_product) {

....

Treasurer MFC

Archived

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

×
×
  • Create New...