Multiple Where statements from one section...

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

Re: [crazyfish] Multiple Where statements from one section...

Hi,

So in the blog section there is series of checkboxes that link to another section called blog_sections?

I've done some testing and I think the best solution would be something like this:

<?php foreach ($blogRecords as $record): ?>
<div class="blog_box">
<?php foreach ($record['thumb'] as $upload): ?>
<?php if ($upload['isImage']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /></a><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<?php endif ?>

<?php endforeach ?>
<div class="large"><?php echo $record['title'] ?></div>

<br/>
<?php echo $record['summary'] ?><br/>

<?php
if($record['blog_sectionsFields:values'][0] > 0){
$additionString = implode(',',$record['blog_sectionsFields:values']);

list($additionsRecords, $additionsMetaData) = getRecords(array(
'tableName' => 'blog_sections',
'where' => "num IN ($additionString)",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
'orderBy' => 'createdDate DESC'
));
}
?>
<?php foreach ($additionsRecords as $record2): ?>
Record Number: <?php echo htmlencode($record2['num']) ?><br/>
Title: <?php echo htmlencode($record2['title']) ?><br/>
Content: <?php echo $record['content']; ?><br/>
<hr/>
<?php endforeach ?>

</div>
<?php endforeach ?>


You will need to swap the field names and section names so that they match the names you have used.

This works by creating a variable called $additionString string that contains a list of num values that have been checked in the blog section in the format x, x, x, x. You will need to change $record['blog_sectionsFields:values'] to the name of the field that contains the values from blog_sections and add :values to the end of it.

This is then added to the where statement of the getRecords function using the IN term. This will only return records that are in the $addtionString. I've also limited the where statement to only return one record, and that will be the newest record using the limit and orderBy keys in the getRecords array.

Let me know if you have any problems implementing this.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Multiple Where statements from one section...

I'm not getting this point
"You will need to change $record['blog_sectionsFields:values'] to the name of the field that contains the values from blog_sections and add :values to the end of it. "

In the table blog_sections, there are six records in which the only field used is title. Those are Press, Events, Inspirations, Installations, Arrivals, Departures.

In the table blog, the variables are in a field named section.

I've tried every variation a non php guy could think of with no results. The page is here http://americadesigns.com/index2.php. The image is coming from the first 12 lines of code which probably should be deleted, and the image moved into your code.

I thank you for your help!