Listing and detail on same page, paging function on listing.

7 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2009   (RSS)

Re: [zaba] Listing and detail on same page, paging function on listing.

By Chris - September 23, 2009 - edited: September 29, 2009

Hi zaba,

That's a little tricky! How about something like this?

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "../CMS Builder.ORIG/cmsAdmin/lib/viewer_functions.php";

list($tal_newsRecords_detail, $tal_newsMetaData) = getRecords(array(
'tableName' => 'tal_news',
'where' => @$_REQUEST['detail'] ? "num = ".(int)$_REQUEST['detail'] : '1',
'limit' => '1',
));
$tal_newsRecord = @$tal_newsRecords_detail[0]; // get first record

// show error message if no matching record is found
if (!$tal_newsRecord) {
print "Record not found!";
exit;
}

list($tal_newsRecords, $tal_newsMetaData) = getRecords(array(
'tableName' => 'tal_news',
'perPage' => '3',
'allowSearch' => '0',
));

?>

<!-- left hand column -->
<?php foreach ($tal_newsRecords as $record): ?>
<h1><a href="?page=<?php echo $tal_newsMetaData['page'] ?>&detail=<?php echo $record['num'] ?>"><?php echo $record['title'] ?></a></h1>
<p><?php echo $record['precis'] ?></p>
<p class="talrule"></p>
<?php endforeach; ?>

<?php if ($tal_newsMetaData['prevPage']): ?>
<a href="<?php echo $tal_newsMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $tal_newsMetaData['page'] ?> of <?php echo $tal_newsMetaData['totalPages'] ?> -

<?php if ($tal_newsMetaData['nextPage']): ?>
<a href="<?php echo $tal_newsMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>

<!--Right hand column -->
<h1><?php echo $tal_newsRecord['title'] ?></a></h1>
<h2><?php echo $tal_newsRecord['initial_para'] ?></h2>
<?php echo $tal_newsRecord['body_text'] ?>


I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Listing and detail on same page, paging function on listing.

By zaba - September 23, 2009

Hi Chris,
Just like to say... you are a genius.

I stripped in the code you posted and it works exactly as I wanted it to do.
Thanks!!!! Thanks!!!! Thanks!!!!
Hope this helps others too

But, I would really like it if you could put in some comments explaining the logic of how you solved this, I don't quite understand all the php coding nuances, but a good book will help on that front, so its just to explain what the code is doing especially in the where clause and the changes you made to the link. It would be much appreciated.

Thanks again!!

Re: [zaba] Listing and detail on same page, paging function on listing.

By Chris - September 23, 2009

Hi zaba,

No problem. :D

Basically, I just changed the detail record lookup to pull its number from a proper query string parameter (?detail=123) and replaced the $record['_link'] with some code to build a query string, preserving the current page.

I hope that makes sense!
All the best,
Chris

Re: [chris] Listing and detail on same page, paging function on listing.

By zaba - September 24, 2009

Thanks Chris,
It makes sense, although I wouldn't have a clue how to do it myself. :-)

I am so glad I found you guys, lost count of how many cmsb installations I have bought/installed. Going the extra mile is in your culture. You guys rock!

Re: [zaba] Listing and detail on same page, paging function on listing.

By Chris - September 29, 2009 - edited: September 29, 2009

Oops,

I've updated the code above to be secure. If you're using it, please change the line:

'where' => @$_REQUEST['detail'] ? "num = {$_REQUEST['detail']}" : '1',

to

'where' => @$_REQUEST['detail'] ? "num = ".(int)$_REQUEST['detail'] : '1',

I've updated the code above to reflect this change.
All the best,
Chris

Re: [chris] Listing and detail on same page, paging function on listing.

By zaba - September 30, 2009

Thanks again Chris,

i'll update the code.
Cheers [:)]