can't believe couldn't find answer to this list viewer question

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 4, 2011   (RSS)

By Codee - December 4, 2011 - edited: December 4, 2011

I scoured the forums for over an hour, then the CMS Cookbook...so I was stunned I didn't see the answer. I want to have a list viewer only load records meeting 2 certain conditions: if a text field is non-blank (that part was easy) AND if an upload field is non-blank. I started with this but it's not correct for the upload field because that's a complex field:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('//','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($modelsRecords, $modelsMetaData) = getRecords(array(
'tableName' => 'models',
'perPage' => '11',
'where' => " (model_testimonial != '') && (image != '')",
));

?>

Someone PLEASE tell me how to correct this so that records load which have the testimonial field non-blank AND have at an image uploaded.
Thanks!

Re: [equinox69] can't believe couldn't find answer to this list viewer question

By Jason - December 4, 2011

Hi,

The reason that this query is difficult is because all upload information is stored in the uploads table, not in the section where you uploaded the image. Uploads are brought in by the getRecords function.

You can accomplish this query by putting in a sub query that will find all the models records that have an upload attached to it.

Try this:

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'models',
'perPage' => 11,
'where' => " model_testimonial != '' AND num IN (
SELECT recordNum FROM `{$TABLE_PREFIX}uploads` WHERE tableName = 'models' AND fieldName = 'image')",
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/