Displaying Results

8 posts by 3 authors in: Forums > CMS Builder
Last Post: October 22, 2013   (RSS)

By shawnpatoka - October 7, 2013

Hi!

Website: www.seenstream.com

Right now, if you search for a zip code from the homepage, it will display records that have either a "platinum" or "gold" or "silver" listing on the top of the list with a star next to their listing and will link to their respected template...and everything that is not one of those is displayed below it. 

(basically... if the record has a checkbox checked in cmsAdmin, it will display on top of the list, clickable, with a star. everything else below it, not clickable, and no star)

How can I make it so everything is displayed in the list where it should be according to the distance that was searched. (i'm using the geotagger plugin) without having the starred ones on top, and the non-starred ones below.

Thanks!

Code is as follows on the 'list.php' page:

<?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' 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',
    ));
  }

?>

displaying results code:

<!-- participating --> 
<?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 ?>

<!-- not participating -->
<?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 ?>

By ross - October 9, 2013

Hi Shawn

Thanks for posting!

My first though here is to just have two different record sets (using getRecords).  One will be just for the checkboxed listings and then one for there rest.  This way, you can have the distance search incorrporated as well as keeping the checkboxed items at the top and the rest below. 

Do you think that would work? 

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By shawnpatoka - October 9, 2013

Hi Ross!

I think that is how i have it set up right now. But I actually need everything all mixed together. 

- Shawn

By shawnpatoka - October 13, 2013

Hi,

Im just wondering if anyone else had any thoughts on this. I've been looking at it more, and I am pretty stumped.

By Chris - October 17, 2013

Hi shawnpatoka,

I think it's more difficult and complicated to have to deal with merging and sorting the two recordsets. If you can get away with it (and it seems like you can in this case,) you may find it easier to use a single getRecords() call and split the list apart by skipping over records using IF and CONTINUE. Here's an example of what I mean:

<?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($addressRecords, $addressMetaData) = 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
    ));
  }

?>

List in order by distance:
<ul>
  <?php foreach ($addressRecords as $record): ?>
    <li><?php echo htmlencode($record['title']) ?></li>
  <?php endforeach ?>
</ul>

List in order of stars:
<ul>

  <!-- first, only list platinums by skipping over everything that doesn't have the 'platinum' field checked -->
  <?php foreach ($addressRecords as $record): ?>
    <?php if (!$record['platinum']) { continue; } ?>
    <li><?php echo htmlencode($record['title']) ?></li>
  <?php endforeach ?>

  <!-- next, only list golds by skipping over everything that doesn't have the 'gold' field checked -->
  <?php foreach ($addressRecords as $record): ?>
    <?php if (!$record['gold']) { continue; } ?>
    <li><?php echo htmlencode($record['title']) ?></li>
  <?php endforeach ?>

  <!-- next, only list silvers by skipping over everything that doesn't have the 'silver' field checked -->
  <?php foreach ($addressRecords as $record): ?>
    <?php if (!$record['silver']) { continue; } ?>
    <li><?php echo htmlencode($record['title']) ?></li>
  <?php endforeach ?>

  <!-- finally, list everything else by skipping over everything that has either the 'platinum', 'gold', or 'silver' field checked -->
  <?php foreach ($addressRecords as $record): ?>
    <?php if ($record['platinum'] || $record['gold'] || $record['silver']) { continue; } ?>
    <li><?php echo htmlencode($record['title']) ?></li>
  <?php endforeach ?>

</ul>

Does that help?

All the best,
Chris

By ross - October 22, 2013

Hi shawnpatoka

Just to do an overly simplified re-cap of what you are looking for, you need your results to be ordered by distance and then have them load into different templates based on whether they are gold, silver or platinum.  

If that's the case, Chris has you on the right track with using just one getRecords and it sounds like you are on the same track with him at that stage.  So now that we have just one getRecords, to get the results loading into a different template based on their gold, silver or platinum status, you can use some simple ifs. What I am thinking is something like this:

<?php 

foreach ($resultsRecords as Rrecord) {

... all your code goes here ...

//

if ($record['gold']) { echo "<a href='gold.php?". $record['num'] ."'>Read More</a>";
if ($record['silver']) { echo "<a href='silver.php?". $record['num'] ."'>Read More</a>";
if ($record['platinum']) { echo "<a href='platinum.php?". $record['num'] ."'>Read More</a>";

}

You'll of course need to make sure you have the appropriate variable in there for $resultsRecord.  Other than that, the if's are pretty straight forward. 

Does this make sense?  And if it does, do you feel like I am on the right track here?

Let me know any questions. Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By shawnpatoka - October 22, 2013

Hi,

I'm not on my regular computer to test it out, but that does look like it should work.

thank you guys very much! I really appreciate it.