Help with Where Clause Checking if an Upload Exists

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 24, 2013   (RSS)

Hi there,

I have a two-stage query problem. The first part loads a category list. Then for each category loaded, we'd like to pull a random product which matches that category AND which has an image uploaded into a multi-upload field. I'm close but can't quite get the image check to fly. The current iteration looks like:

// load 'categories'
  list($categoriesRecords, $categoriesMetaData) = getRecords(array(
    'tableName'   => 'categories',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

--- LATER ---
 
               <ul class="thumbnails">
                <?php foreach ($categoriesRecords as $record):
                      // load 1 random sample with an image from 'products' table for each category
                    $cat = trim($record['name']);

                  list($productsRecords, $productsMetaData) = getRecords(array(
                    'tableName'   => 'products',
                    'limit'       => '1',
                    'orderBy'     => 'RAND()',
                    'loadUploads' => true,
                    'allowSearch' => false,
                    'where'     => "CHAR_LENGTH(images) > 0 AND category LIKE '%\t".$cat."%\t'",
                    // 'where'         => "`category` LIKE '%\t".$cat."%\t'",
                     'debugSql'      => '1',
                  ));?>

                    <?php foreach ($productsRecords as $product): ?>
                    ---- DISPLAY SOME STUFF ----

                   <?php endforeach; // end single product sample load ?>
                  <?php endforeach; // end category selection loop ?>

At the moment I keep getting failure messages like the following after a single loop : 

    • MySQL Error: Unknown column 'images' in 'where clause'

Have also tried 'where' => "`images` != NULL",  also without success.

Any pointers on where I'm going off the rails. I can't see this code clearly anymore.

Thanks,

J.