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)

By zaba - September 22, 2009 - edited: September 23, 2009

Can anyone help my time is ticking....
Hi I have a left hand column which lists a number of stories, at the foot of this column is the paging function to load the next stories. But. On the same page I have in the right column the detail of the content when clicked from the left hand column.
The problem here is I have 2 numbers in the url, one for the page and one for the record. The detail page sees the last number in the url and thinks it is the record number, when infact it is the page number.

If I click on the next page, then click on a story in the left column I want it to stay on this page and also pick up the correct story. I am baffled as how to do this.

Basically, I am wanting a list and detail on the same page with a prev next page to affect only the list and maintain the selected detail story.

I hope this make sense.

I can post the actual url, but I'd rather not make this public.



I'll paste the relevant code here.

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

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


list($tal_newsRecords_detail, $tal_newsMetaData) = getRecords(array(
'tableName' => 'tal_news',
'where' => whereRecordNumberInUrl(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;
}
?>

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

<!--Paging -->
<?php
list($tal_newsRecords, $tal_newsMetaData) = getRecords(array(
'tableName' => 'tal_news',
'perPage' => '3',
'allowSearch' => '0',
));

?>

<?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'] ?>

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: [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 [:)]