Problem with 'WHERE'

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 18, 2012   (RSS)

OK, I’m lost again...

I’m trying to get a count of how many images exist in a record so that I can eventually compare that with the number of uploads in a variable.

I’m getting unwanted results in my 'WHERE' as described below and don’t know how to resolve the problem.

Hope someone can shed some light on this.

Thanks,

Jerry Kornbluth
________________________

On a simple test page when I use:
<?php
// load records
list($client_uploadsRecords, $client_uploadsMetaData) = getRecords(array(
'tableName' => 'client_uploads',
'where' => "first_name= 'Gerald' AND last_name= 'Kornbluth' AND project_title= 'Participation 2012'",
'debugSql' => true,
));
?>
<?php foreach ($client_uploadsRecords as $record): ?>
<?php foreach ($record['uploads'] as $upload): ?>

<?php $count = count($record['uploads']);?>

<?php endforeach ?>
<?php endforeach ?><br />
There are <?php echo $count ?> uploads

Everything seems to work fine

debug returns:
WHERE (first_name= 'Gerald' AND last_name= 'Kornbluth' AND project_title= 'Participation 2012') and I get a count of how many uploaded images there are in the 'uploads' field of that specific record.

When I try to implement the same code around line 345 in a more complex upload page (attached), the count is blank, and debug returns a 'WHERE' with all of the available fields in that record listed (some repeated), IE:
WHERE (first_name= 'Gerald' AND last_name= 'Kornbluth' AND project_title= 'Participation 2012' AND (`num` = '4') AND (`createdDate` = '2008-07-13 21:10:33') AND (`createdByUserNum` = '2') AND (`updatedDate` = '2012-10-14 12:30:32') AND (`updatedByUserNum` = '4') AND (`email` = 'me@myemailaddress.com') AND (`first_name` = 'Gerald') AND (`last_name` = 'Kornbluth') AND (`street_address` = '123 4th st') AND (`city` = 'Lake Worth') AND (`state` = 'FL') AND (`zip` = '33467-7227') AND (`day_phone` = '561 234 5678') AND (`evening_phone` = '123 456 6789') AND (`cell_phone` = '123456777') AND (`web_site` = 'JKWebdesigns.com') AND
(`ok_to_publish_phone_contact_information` = '1') AND (`ok_to_publish_address_contact_information` = '1') AND (`ok_to_publish_email_contact_information` = '1'))
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

exhibition_uploads5.php 41K

Re: [gkornbluth] Problem with 'WHERE'

Hi Jerry,

Is this where clause used after a form is submitted or is there any data passed in the URL? As I think the most likely option is that getRecords is performing a search as well as using your WHERE statement. You should be able to fix this using the following code:

<?php
// load records
list($client_uploadsRecords, $client_uploadsMetaData) = getRecords(array(
'tableName' => 'client_uploads',
'where' => "first_name= 'Gerald' AND last_name= 'Kornbluth' AND project_title= 'Participation 2012'",
'debugSql' => true,
'allowSearch' => false, // optional, defaults to true, adds search info from query string
'loadUploads' => true, // optional, defaults to true, but set here just to be sure.

));
?>
<?php foreach ($client_uploadsRecords as $record): ?>
<?php foreach ($record['uploads'] as $upload): ?>

<?php $count = count($record['uploads']);?>

<?php endforeach ?>
<?php endforeach ?><br />
There are <?php echo $count ?> uploads


Let me know if this doesn't work.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com