I have been porting a site from osc to zencart and everything has been going along smoothly. On osc there was a mod installed to pick a random category image from a product in that category. Since it didn't exist on zencart I have been trying to write something to modify.

There may be a better way to do this, but I haven't been able to get the query to work.

I modified the module category_row.php and added this:

PHP Code:
global $db;

    
$rand_category_query $db->Execute(        "select p.products_image as img from zen_products p ".
                                        
"LEFT OUTER JOIN zen_products_to_categories ptc ON ".
                                        
"p.products_id = ptc.products_id ".
                                        
"WHERE LENGTH(p.products_image) > 0 ".
                                        
"AND ptc.categories_id = ".$categories->fields['categories_id'].
                                        
" ORDER BY rand( ) LIMIT 1");

    
$rand_img $db->Execute($rand_category_query);
    
$random_cat $rand_img->fields['img']; 
But the query comes back with nothing. When I echo the statement and run it in my database it works just fine.

Any help would be appreciated.