Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Location
    South Florida
    Posts
    197
    Plugin Contributions
    0

    Default 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??

    PHP Code:
      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'];
        }
      } 

  2. #2
    Join Date
    Apr 2008
    Location
    South Florida
    Posts
    197
    Plugin Contributions
    0

    Default Re: Random Product Image As Category Image

    Anyone have any thoughts on this?

  3. #3
    Join Date
    Mar 2010
    Posts
    1
    Plugin Contributions
    0

    Default Re: Random Product Image As Category Image

    PHP Code:
     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'];

        }
      } 

 

 

Similar Threads

  1. v139 Random Products Image instead of Category Icon
    By Webmart in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 16 Nov 2012, 11:16 AM
  2. Remove product image from product page NOT category image
    By rgoetz in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 3 Aug 2011, 11:25 AM
  3. Different category image and product image
    By audiomandan in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 31 Mar 2011, 08:55 AM
  4. image per category with no product image
    By momora in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 1 Oct 2009, 03:00 PM
  5. use random product image as sub cat image
    By si86 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 15 Aug 2009, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg