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: [chris] Exclude record(s) from viewer results?

By jghoward - October 6, 2009 - edited: October 6, 2009

The code snippet you mentioned looks useful, but how do I implement it in my page?

I'm using the code generator, so I have this at the top of my page:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "/home/content/12/4805312/html/cmsAdmin/lib/viewer_functions.php";

list($listingsRecords, $listingsMetaData) = getRecords(array(
'tableName' => 'listings',
'allowSearch' => '0',
));


I'm using Google Maps and I want to show only one marker for each address. Some adresses have several unit types, so I just want to show one.

The code I'm using shows all of them:
<?php foreach ($listingsRecords as $record): ?>

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; ?>

}


Can you tell me how to use the code you suggested? This will be helpful to me, as there are other situations on the site (slideshows) where I will need to know how to exclude listings.

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