Jump to content

Recordset Navigation


globetrottingmike

Recommended Posts

Hi All,

 

What would be the best way to create links for a results page which is paginated, but the page number is unknown? An example would be that there are 50 results with 10 results page, so pagination would show 5 pages of results. That bit is fine. When I go to add a new record and the ask the insirt record form to redirect to this page, it will need to know that the 51st record is at the top of page 6.

 

I know this can be done as other sites have this set up. PunBB forums for example have a normal paginated page result of www.site.com/viewtopic.php?id=6298&p=2 (where id= the topic id and p= the paginated page number of the results). But when the paginated page result in unknown the us the url of: www.site.com/viewtopic.php?pid=82811#p82811 (where pid= the post id). So they work out the paginated page fromt he post id.

 

Does anyone have pagination experience who can try to help me replicate this.

 

Thanks in advance for any help anyone can give.

Link to comment
https://forums.phpfreaks.com/topic/123001-recordset-navigation/
Share on other sites

Thanks BlueSky for your quick response, however what I need to know is how to set up pagination for a hyperlink where I don't know which page number that forum post is on. Below is a PunBB viewtopic.php extract which does this:

// If a post ID is specified we determine topic ID and page number so we can redirect to the correct message
if ($pid)
{
$result = $db->query('SELECT topic_id FROM '.$db->prefix.'posts WHERE id='.$pid) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
	message($lang_common['Bad request']);

$id = $db->result($result);

// Determine on what page the post is located (depending on $pun_user['disp_posts'])
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY posted') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
$num_posts = $db->num_rows($result);

for ($i = 0; $i < $num_posts; ++$i)
{
	$cur_id = $db->result($result, $i);
	if ($cur_id == $pid)
		break;
}
++$i;	// we started at 0

$_GET['p'] = ceil($i / $pun_user['disp_posts']);
}

 

Does anyone understand this and would be wiling to help me integrate it into my pagination solution?

 

Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/123001-recordset-navigation/#findComment-635155
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.