showing specific records and linking to different templates
3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 23, 2013 (RSS)
By shawnpatoka - July 16, 2013
So i swear this was working a couple months ago...
So on my website, seenstream.com, I have a zip code search that displays a list of closest results. On the top of that list are the main "Participating Bars"
Each participating bar has check boxes in the backend to designate which template it should link to... Platinum, Gold, or Silver. The Platinum should link to a.php, Gold links to b.php, Silver links to c.php.
But my problem is as soon as i uncheck the "platinum" checkbox in its record in the backend, and check "gold" it then does not show up in the list. When it should show up, right next to the Platinum results, and link to b.php.
my code above the DOCTYPE is:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php require_once "cmsAdmin/lib/viewer_functions.php"; ?>
<?php if (!@$GLOBALS['GEOCODER_PLUGIN']) { die("You must activate the Geocoder plugin before you can access this page."); } ?>
<?php
$kmOrMiles = 'miles'; // can be 'miles' or 'km'
// set default values
if (!array_key_exists('fromAddress', $_REQUEST)) { $_REQUEST['fromAddress'] = '10001'; } // this is the default address/postalcode if none entered
if (!@$_REQUEST['maxDistance']) { $_REQUEST['maxDistance'] = '50000'; } // this will include all results
// get coordinates
list($myLat, $myLng) = geocodeAddress( @$_REQUEST['fromAddress'] );
// error checking
$errorsAndAlerts = '';
if (@$_REQUEST['search']) {
if (!@$_REQUEST['fromAddress']) { $errorsAndAlerts .= "No address entered!<br/>\n"; }
elseif (!$myLat || !$myLng) { $errorsAndAlerts .= "We couldn't determine your location, please try again!<br/>\n"; }
}
// get records
$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($trueAddressRecords, $trueAddressMetaData) = getRecords(array(
'tableName' => 'participating_bars',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
'where' => "platinum = '1'",
));
}
// get records
$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($falseAddressRecords, $falseAddressMetaData) = getRecords(array(
'tableName' => 'participating_bars',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
'where' => "platinum = '0'",
'perPage' => '5',
));
}
?>
and my code in the search area is:
<?php if (@$_REQUEST['search'] && !$errorsAndAlerts): ?>
<?php foreach ($trueAddressRecords as $record): ?>
<a href="http://www.seenstream.com/<?php if($record['platinum'] ==1): ?>
a.php?<?php echo $record['_link'] ?>
<?php elseif ($record['gold'] ==1): ?>
b.php?<?php echo $record['_link'] ?>
<?php elseif ($record['silver'] ==1): ?>
c.php?<?php echo $record['_link'] ?>
<?php endif ?>" />
<div class="listing-container"><?php foreach ($record['logo'] as $index => $upload): ?><img class="barlogo" src="<?php echo $upload['urlPath'] ?>" /><?php endforeach; ?>
<div class="listing-container-heading"><h2><?php echo $record['title']; ?></h2></div>
<p><?php echo $record['address']; ?><br /><?php echo $record['phone_number']; ?><br />(<?php echo floor($record['_distance'] * 10) / 10; ?> <?php echo $kmOrMiles ?> away)</p>
<div class="star"></div></div>
</a>
<?php endforeach ?>
<?php endif ?>
<?php if (@$_REQUEST['search'] && !$errorsAndAlerts): ?>
<?php foreach ($falseAddressRecords as $record): ?>
<!--<?php echo htmlspecialchars($record['title']); ?>,-->
<div class="listing-container"><img class="barlogo" src="i/barlogo_seenstream.jpg" /><div class="listing-container-heading"><h2><?php echo $record['title']; ?></h2></div><p><?php echo $record['address']; ?><br /><?php echo $record['phone_number']; ?><br />(<?php echo floor($record['_distance'] * 10) / 10; ?> <?php echo $kmOrMiles ?> away)</p></div>
<?php endforeach ?>
<?php if (!$falseAddressRecords): ?>
No results found!
<?php endif ?>
<?php endif ?>
Please let me know if you need any other information, or have any other questions for me.
again...
if you go to www.seenstream.com, type in like "54952", it should show 3 bars with stars next to them. 1 to a template a.php and the other 2 to the template b.php
By gregThomas - July 18, 2013
Hi shawnpatoka,
I think the issue is that you don't have a clause in your trueAddressRecords where statement to retrieve gold and silver results, it's only retrieving results for platinum. You should find that the bar currently appears on page 19-21 of your falseAddressRecords list once platinum is deselected. I think you just need to add some extra lines to your trueAddressRecords statement to retrieve the gold and silver results as well, and make sure these don't appear in your falseAddressRecords:
// get records
$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($trueAddressRecords, $trueAddressMetaData) = getRecords(array(
'tableName' => 'participating_bars',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
'where' => "platinum = '1' OR gold = '1' OR silver = '1'",
));
}
// get records
$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($falseAddressRecords, $falseAddressMetaData) = getRecords(array(
'tableName' => 'participating_bars',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles), // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
'where' => "platinum = '0' AND gold = '0' AND silver = '0'",
'perPage' => '5',
));
}
?>
So if you add the new where statements to your current code you should find that the true results now collect all of the platinum gold and silver results, and the false address records will return anything that doesn't have these three checkboxs selected.
Let me know if you have any questions.
Cheers
Greg
PHP Programmer - interactivetools.com
By shawnpatoka - July 23, 2013
thank you very much Greg. I originally tried doing something like that, but did not have "OR" in there.
Thanks again!