Previous and next records on a Detail page?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 8, 2013   (RSS)

By 5fish - April 5, 2013

Is there a way to include links to the previous and next records on a Detail page?

I found

http://www.interactivetools.com/forum/forum-posts.php?postNum=2202277#post2202277

But doesn't seem to work for me or I am missing something.

By 5fish - April 8, 2013

Close ...

http://www.petersmithconstruction.ca/glistted.php

calls the details page and the first & last links work - next & previous do not work

code below

<?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('/home/petersmi/public_html/','','../','../../','../../../');
  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
  list($gallerytestRecords, $gallerytestMetaData) = getRecords(array(
    'tableName'   => 'gallerytest',
    'where'       => whereRecordNumberInUrl(33),
    'limit'       => '1',
  ));
  $gallerytestRecord = @$gallerytestRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$gallerytestRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;
  }
 //Get prev/next links using the blog num
  list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array(
    'tableName' => 'gallerytest',
    'recordNum' => $gallerytest['num'],
    'orderBy'   => 'createdDate'
  ));
?>

     <!-- show previous and next links -->
Previous Record: <a href="<?php echo (@$prevRecord['_link'])? $prevRecord['_link'] : '?' ; ?>">Previous</a><br>
                Next Record: <a href="<?php echo @$nextRecord['_link']; ?>" >Next</a>
                First Record: <a href="<?php echo (@$firstRecord['_link'])? $firstRecord['_link'] : '?' ; ?>" >First</a>
                Last Record: <a href="<?php echo @$lastRecord['_link'] ?>">Last</a><br>

Attachments:

gallerydetailsted.php 6K

By gregThomas - April 8, 2013

Hi,

I think I can see the problem.

You're calling the variable $gallerytest['num'], but I can't see where that variable is being created, I think you might need to change your code to this:

<?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('/home/petersmi/public_html/','','../','../../','../../../');
  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
  list($gallerytestRecords, $gallerytestMetaData) = getRecords(array(
    'tableName'   => 'gallerytest',
    'where'       => whereRecordNumberInUrl(33),
    'limit'       => '1',
  ));
  $gallerytestRecord = @$gallerytestRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$gallerytestRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;
  }
 //Get prev/next links using the blog num 
  list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array( 
    'tableName' => 'gallerytest', 
    'recordNum' => $gallerytestRecord['num'], 
    'orderBy'   => 'createdDate'
  ));
?>

So I've changed the code so that it uses the $gallerytestRecord variable. Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By 5fish - April 8, 2013

Thank you!  Works great!