Display results from different sections

14 posts by 2 authors in: Forums > CMS Builder
Last Post: October 27, 2010   (RSS)

Re: [degreesnorth] Display results from different sections

By Chris - October 25, 2010

Hi degreesnorth,

Can you explain what you mean by "group the results"? What are the results you're getting now and what would grouped results be?

I also don't understand what you mean by "pulling across all of the data".

Do I need to add something to the results page to get this to display as well?


What exactly do you want to add to your results page?

But then how do I deal with the "php for each" statement, ie... <?php foreach ($river_cruisesRecords as $record): ?> and <?php foreach ($escorted_toursRecords as $record): ?>
... do I need to add these somehow?


Yes, you'll need to add those. Taking a look at your attached page, I can see what's going wrong:

<?php foreach ($toursRecords as $record): ?>
<?php foreach ($escorted_toursRecords as $record): ?>
... record display code ...
<?php endforeach ?>
<?php endforeach ?>


You don't want to do that — that's called a nested loop. You'll want to do this instead:

<?php foreach ($toursRecords as $record): ?>
... record display code ...
<?php endforeach ?>
<?php foreach ($escorted_toursRecords as $record): ?>
... record display code ...
<?php endforeach ?>


Alternately, you can "merge" your arrays so you can use a single foreach:

<?php $mergedRecordSets = array_merge($toursRecords, $escorted_toursRecords) ?>
<?php foreach ($mergedRecordSets as $record): ?>
... record display code ...
<?php endforeach ?>


You can add all your record sets into the array_merge call:

<?php $mergedRecordSets = array_merge($toursRecords, $escorted_toursRecords, $polar_toursRecords, $river_cruisesRecords) ?>
<?php foreach ($mergedRecordSets as $record): ?>
... record display code ...
<?php endforeach ?>


Does that help?
All the best,
Chris

By degreesnorth - October 26, 2010

The last string of code works a dream. Thanks!

So, just one last question to solve this section... the array for grouping the days. The days are currently in a section editor, with the 'days' field each a seperate file from 1 to 30. If I need to group these into:
- any/all (ie, not important)
- 1 to 5 days
- 5 to 10 days
- 10 to 15 days
- 15 to 20 days
- 20 to 25 days
- more than 25 days

How would I go about doing this?

Re: [degreesnorth] Display results from different sections

By Chris - October 27, 2010

Hi degreesnorth,

I think you'll want to use the [url http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html]_min and _max search suffixes.[/url]

For example, you could put this at the very top of your script (before your getRecords()):

$days = @$_REQUEST['number_of_days'];
delete $_REQUEST['number_of_days'];
if ($days == '1 to 5 days' ) { $_REQUEST['number_of_days_min'] = 1; $_REQUEST['number_of_days_max'] = 5; }
if ($days == '5 to 10 days' ) { $_REQUEST['number_of_days_min'] = 5; $_REQUEST['number_of_days_max'] = 10; }
if ($days == '10 to 15 days' ) { $_REQUEST['number_of_days_min'] = 10; $_REQUEST['number_of_days_max'] = 15; }
if ($days == '15 to 20 days' ) { $_REQUEST['number_of_days_min'] = 15; $_REQUEST['number_of_days_max'] = 20; }
if ($days == '20 to 25 days' ) { $_REQUEST['number_of_days_min'] = 20; $_REQUEST['number_of_days_max'] = 25; }
if ($days == 'more than 25 days') { $_REQUEST['number_of_days_min'] = 26; }


Does that help?
All the best,
Chris