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: [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.