Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
can't believe couldn't find answer to this list viewer question

 

 


equinox69
User

Dec 4, 2011, 1:59 AM

Post #1 of 3 (990 views)
Shortcut
can't believe couldn't find answer to this list viewer question Can't Post

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:

Code
<?php header('Content-type: text/html; charset=utf-8'); ?> 
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// 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!


(This post was edited by equinox69 on Dec 4, 2011, 12:43 PM)


Jason
Staff / Moderator


Dec 4, 2011, 9:15 AM

Post #2 of 3 (959 views)
Shortcut
Re: [equinox69] can't believe couldn't find answer to this list viewer question [In reply to] Can't Post

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:


Code
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 - Programmer 
interactivetools.com

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


equinox69
User

Dec 4, 2011, 12:44 PM

Post #3 of 3 (921 views)
Shortcut
Re: [Jason] can't believe couldn't find answer to this list viewer question [In reply to] Can't Post

perfectamente bien Jason! Thank you!