paging function that starts from no. of records returned after 5.

11 posts by 2 authors in: Forums > CMS Builder
Last Post: May 3, 2010   (RSS)

Re: [zaba] paging function that starts from no. of records returned after 5.

By Jason - April 28, 2010

Hi,

We can definitely do that, we just need to change our code a little. Replace the code at the php top of your page with this:

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



list($newsRecords_detail, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => @$_REQUEST['detail'] ? "num = ".(int)$_REQUEST['detail'] : '1',
'limit' => '1',
));

$newsRecord = @$newsRecords_detail[0]; // get first record


// show error message if no matching record is found
if (!$newsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

//Get the first 5 news records
list($firstRecords,$firstMetaData)=getRecords(array(
'tableName'=>'news',
'allowSearch'=>false,
'limit'=>5,
));

//create a list of the first 5 new record numbers
$recordList="";

foreach($firstRecords as $first){
if($recordList){$recordList.=",";}
$recordList.=$first['num'];
}

//get news records, excluding the first 5
list($newsListRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'perPage' => '5',
'allowSearch' => '0',
'where' => "num NOT IN (".mysql_escape($recordList).")",
));

?>


So what we did here was to create a list of the first 5 records, then told the database to only return records that didn't match that list.

Give this a try and let me know if you run into any issues.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] paging function that starts from no. of records returned after 5.

By zaba - April 28, 2010

Thanks Jason, this works but what is happening is the detail content is not showing the first record of the page, (it is sowing the very first record not the 6th) and likewise when you go to the second page it shows the very first record and not the 11th. Please could you help me fix this.
Really appreciate your help.

Re: [zaba] paging function that starts from no. of records returned after 5.

By Jason - April 28, 2010

Hi,

I took a look. The problem we were having is that we were still selecting our news record from the full list of records, not the shortened list that we had created.

I changed this to select from the shorter list, and now the news-archive will always display the first record that is displayed in the list on the side. Take a look and make sure everything is working the way you want it to.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] paging function that starts from no. of records returned after 5.

By zaba - April 28, 2010

Hi Jason, thanks for all your work on this. It does display the first record of each page but when you click on a link from the list on the right it still displays the first record, almost there I think. Once again you guys are amazing!!!

Re: [zaba] paging function that starts from no. of records returned after 5.

By Jason - April 29, 2010

Hi,

I revisited the issue we were having. I changed it so that if the user clicks on a specific news story, it will display that. If not, it will display the first record in the list.

Let me know if this now works the way you want.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] paging function that starts from no. of records returned after 5.

By zaba - April 30, 2010

Thanks Jason, just had a look, one little issue, if you (on page one) click on the right hand links it loads the correct page, but if you then click on next (page 2) it doesn't load the correct story, likewise if you do it in the opposite direction. I'd really appreciate you taking another look. Sorry about that. :-)

Re: [zaba] paging function that starts from no. of records returned after 5.

By Jason - April 30, 2010

Hi,

No problem. What's happening right now is that if a story has not been selected, the first story in the list is being displayed. If a story is selected, then that story will continue to be displayed until a different story is selected. If a story is selected and the page is changed, it doesn't automatically display a different story. Do you want it to display the first story in the list when a page is changed regardless if a story is being shown already?

Let me know and we'll get it sorted out.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] paging function that starts from no. of records returned after 5.

By zaba - April 30, 2010

Hi Jason, yes I think it makes more sense to reveal the first story in that set of stories, rather than remain on the story being shown. It makes sense to do this to me anyway as that's what I was expecting to happen when I did it the first time.
Thanks again.

Re: [zaba] paging function that starts from no. of records returned after 5.

By Jason - May 3, 2010

Hi,

I made a small change to the code. Now every time the "next" or "prev" page buttons are clicked, the page will display the first story in the list.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/