Log in

View Full Version : Please help with pagenav


Lea Verou
11-15-2005, 05:25 AM
I'd like to add a pagenav to a mod I'm developing.
However no matter what I read in the API documentation or saw in vb php files I still can't understand how to use the construct_page_nav() function.
I can't understand what to put as it's variables. :(
Anyone that does? :o :nervous:

Thanks in advance :)

cinq
11-15-2005, 05:33 AM
$vbulletin->input->clean_array_gpc('r', array(
'perpage' => TYPE_INT,
'page' => TYPE_INT
));

// $TOTALNUMBEROFROWS = total number of rows you have. Probably obtain this from a query and assign $db->num_rows($query) to this.
// $NOOFRESULTSPERPAGE = how many results you want per page. eg. 10 per page or 20 per page.

$perpage = $NOOFRESULTSPERPAGE;
$pagenumber = $vbulletin->GPC['page'];
$pagecount = ceil($TOTALNUMBEROFROWS / $perpage);
$pagenumber = iif(!is_numeric($pagenumber) OR $pagenumber < 1 OR $pagenumber > $pagecount, 1, $pagenumber);
$offset = ($pagenumber-1) * $perpage;

if(empty($vbulletin->GPC['page']))
$page = 1;
else
$page = $vbulletin->GPC['page'];
$pagenav = construct_page_nav($page, $perpage, $TOTALNUMBEROFROWS, "yourpage.php","");


Then in your main query which will limit results, use this as the LIMIT condition.

LIMIT $offset,$perpage


Now place $pagenav in your template wherever you want it to show.

Hope this helps. It's how I do it at least.
:)

Lea Verou
11-15-2005, 05:34 AM
It looks very helpful, thanks so much! :)
I'll try to use it and come again if I have any questions :)

It looks very helpful, thanks so much! :)
I'll try to use it and come again if I have any questions :)

It really helped but I can't make the LIMIT to work :(
When I put LIMIT every page is displayed as if it was the first page :confused:

Oreamnos
12-11-2005, 02:37 AM
i don't think this will help Michelle but don't forget the '?' after yourpage.php?
$pagenav = construct_page_nav($page, $perpage, $TOTALNUMBEROFROWS, "yourpage.php?","");

michelle, if you post your code we might be able to help a bit more.

cinq, worked great! thanks