Zen Cart Logo
Forums / General Questions / Random Product Image As Category Image

Random Product Image As Category Image

Locked

Views: 732

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
8 Apr 2010, 8:55 PM
#1
fotofx avatar

fotofx

Zen Follower

Join Date:
Apr 2008
Location:
South Florida
Posts:
195
Plugin Contributions:
0

Random Product Image As Category Image

I am trying to modify the zen_get_categories_image function to provide a random product image from within that category if no category image exists. I thought I had it but although no errors, it is not working as I expected. Any obvious errors??

  function zen_get_categories_image($what_am_i) {
    global $db;

    $the_categories_image_query= "select categories_image from " . TABLE_CATEGORIES . " where categories_id= '" . $what_am_i . "'";
    $the_products_category = $db->Execute($the_categories_image_query);

    if ($the_products_category->fields['categories_image'] !=NULL){
    return $the_products_category->fields['categories_image'];
    } else {
      $random_product_query= "select products_image from " . TABLE_PRODUCTS . " where master_categories_id= '" . $what_am_i . "'";
     $random_product_raw = $db->Execute($random_product_query);
     $random_product_image_rand = array_rand($random_product_raw,1);
     $the_products_category->fields['categories_image'] = $random_product_image_rand[0];
     return $the_products_category->fields['categories_image'];
    }
  }
11 Apr 2010, 5:41 PM
#2
fotofx avatar

fotofx

Zen Follower

Join Date:
Apr 2008
Location:
South Florida
Posts:
195
Plugin Contributions:
0

Re: Random Product Image As Category Image

Anyone have any thoughts on this?

11 Apr 2010, 9:25 PM
#3
dagon avatar

dagon

New Zenner

Join Date:
Mar 2010
Posts:
1
Plugin Contributions:
0

Re: Random Product Image As Category Image

 function zen_get_categories_image($what_am_i) {
    global $db;

    $the_categories_image_query= "select categories_image from " . TABLE_CATEGORIES . " where categories_id= '" . $what_am_i . "'";
    $the_products_category = $db->Execute($the_categories_image_query);

    if (!empty($the_products_category->fields['categories_image'])){
    return $the_products_category->fields['categories_image'];
    } else {
      $random_product_query= "SELECT products_image FROM " . TABLE_PRODUCTS  . "
      WHERE master_categories_id= '" . $what_am_i . "' ORDER BY rand() LIMIT 1";
      $the_products_category = $db->Execute($random_product_query);
     return $the_products_category->fields['products_image'];

    }
  }