Exclude record(s) from viewer results?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 6, 2009   (RSS)

By jghoward - August 31, 2009

I'm working on a site that lists property rentals, and my client has units at different price points at the same street address. Since I'm populating Google Maps, slideshows, and overall site navigation with list data, there are times when I don't want to show duplicate addresses, nor list individual units.

I'm thinking I will maintain separate records for each unit type, but only display the street address containing those units and link to different types in the main detail page.

However, I do want the user to be able to search the entire list for rental price range. Is there a way to exclude some records in the foreach loop in only some viewers?

Also, are there any issues to be aware of when I'm using multiple viewers on the same page? My maps, slideshows, navigation should be on the same page as search. I don't quite understand what the "searchable" option means when generating code, and why it should be disabled sometimes. I could not find it in the docs.

Thanks,
John

Re: [jghoward] Exclude record(s) from viewer results?

By Chris - September 1, 2009 - edited: September 1, 2009

Hi John,

Is there a way to exclude some records in the foreach loop in only some viewers?


Absolutely! You have complete control over which records are filtered and which are displayed. If you can explain exactly how you want to decide which records to show, we can show you how to do so.

For example, here's some code that would build a list of records from a section called "rentalunit", but filter any which have duplicate entries in their "address" field:

$rentalunitRecords = array();
$query = "SELECT * FROM cms_rentalunit GROUP BY address";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)) {
array_push($rentalunitRecords, $record);
}


Also, are there any issues to be aware of when I'm using multiple viewers on the same page? My maps, slideshows, navigation should be on the same page as search. I don't quite understand what the "searchable" option means when generating code, and why it should be disabled sometimes. I could not find it in the docs.


"By default automatic searching is enabled. If you have multiple viewers on one page you may want some viewers to always show all results and ignore search keywords."

Basically, your List Viewer pages can double as search results pages, but that might stop making sense when you have multiple List Viewers on a single page. For example, you probably wouldn't want your navigation to be "searchable" by a visitor.

Please provide more details on how you want to filter your results (and maybe a sample List page, so we can see what your fields are called) and we'll see what we can do to help.
All the best,
Chris

Re: [jghoward] Exclude record(s) from viewer results?

By Chris - October 6, 2009

Hi John,

How about this approach instead?

<?php $latlngsAlreadySeen = array(); ?>
<?php foreach ($listingsRecords as $record): ?>

<?php
// don't create two markers for the same latlng
$latlng = $record['latitude'] . ',' . $record['longitude'];
if (array_key_exists($latlng, $latlngsAlreadySeen)) { continue; } // skip latlngs we've already seen
$latlngsAlreadySeen[$latlng] = true; // mark latlng as seen
?>

var point = new GLatLng(<?php echo $record['latitude'] ?>,<?php echo $record['longitude'] ?>);
var marker = createMarker(point,'<?php echo htmlspecialchars($record['street_address'], ENT_QUOTES) ?>, <?php echo htmlspecialchars($record['city'], ENT_QUOTES) ?> <br /><a href="<?php echo $record['_link'] ?>" target="_blank">View Property Details</a>')
map.addOverlay(marker);

<?php endforeach; ?>


That will avoid creating extra markers for the same Latitude & Longitude pair.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris