Showing the number of search results found

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 27, 2013   (RSS)

By CommonSenseDesign - February 27, 2013 - edited: February 27, 2013

Hi, All.

Is there a way of showing the number of records found on the search results page? Better yet, is it possible to tell the viewer which range of results they're looking at? i.e. If there are more than one page of results, the second might say "Items 11-20 out of 55 found".

Thanks,

Nigel Gordijk

By gregThomas - February 27, 2013

Hi Nigel,

If you're using a getRecords function to retrieve your results, this information is easy to display. It is accessible via the meta data of your results in the pageResultsStart, pageResultsEnd and totalRecords keys. Here is some example code:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records from 'blog'
  list($blogRecords, $blogMeta) = getRecords(array(
    'tableName'   => 'blog',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  echo $blogMeta['pageResultsStart'].'<br>'; //start number for current page results.
  echo $blogMeta['pageResultsEnd'].'<br>'; //End number for current page results.
  echo $blogMeta['totalRecords'].'<br>'; //Total records

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css">
    body          { font-family: arial; }
    .instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
  </style>
 </head>
<body>
<p>Results <?php echo $blogMeta['pageResultsStart']; ?> - <?php echo $blogMeta['pageResultsEnd']; ?> out of  <?php echo $blogMeta['totalRecords']; ?> found</p>
  
</body>
</html>

This is just example code, so you'll need to change the variables and getRecords function to work with your example. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By CommonSenseDesign - February 27, 2013

Thanks, Greg - I'll give this a shot.