View Full Version : Pagination Help
AlienSector
12-10-2004, 12:42 AM
I am hoping that possibly Brian or another developer will see this and can possibly help with this issue that has been pestering me for the past 2 weeks now. I almost thought I had made progress but obviously I am confused and losing myself somewhere in the coding :).
I am looking for help with pagination and how to build such using vBulletin's coding. What I am doing is pulling items from a database and displaying say 8 per page, then I would like vBulletin to build its navigation bar for the remaining pages and next/previous pages.
I have looked at various files in vBulletin but I am about clueless. Any help with this would be very much appreciated as a large part of our database requires this and is basically useless without it.
If anyone would be nice enough to help guide me into getting this to work, I'd appreciate it so much :).
Brian
12-10-2004, 12:51 AM
$perpage = 50;
$itemcount = $DB_site->query_first("SELECT COUNT(*) AS count FROM yourtable");
$minlimit = intval(($pagenumber - 1) * $perpage + 1);
$maxlimit = intval($pagenumber * $perpage);
if ($maxlimit > $itemcount['count'])
{
$maxlimit = $itemcount['count'];
if ($minlimit > $itemcount['count'])
{
$minlimit = $itemcount['count'] - $perpage;
}
}
if ($minlimit <= 0)
{
$minlimit = 1;
}
$limit = ($minlimit - 1) . ',' . $perpage;
$getstuff = $DB_site->query("SELECT * FROM yourtable LIMIT $limit");
$pagenav = construct_page_nav($itemcount['count'], 'filename.php');
That should be enough to give you the general idea. :)
AlienSector
12-13-2004, 03:29 AM
Of course I'd see this 3 days later heh, thanks Brian, I will look over that and see if I can manage to get it working with our current scripting :).
AlienSector
12-13-2004, 03:41 AM
Brian, while that does, in a way work, I am not quite sure how to get that working with a module created for vBAdvanced seeing as it does not want to take correctly with &page= added to the URL.
Any suggestions on this? I could be overlooking something so simple.
AlienSector
01-18-2005, 06:49 PM
Hey Brian
Sorry to bring up an older topic, though since this one was around I figured there was no need to create a new one for the same thing.
I used the above coding and while the limit is right and the display works (i.e. the pages and such), when I click to go to the next page, it does not work (i.e. still shows the same results, no limited results or new results).
$keywords = $_GET['s'];
$itemcount = $DB_site->query_first("SELECT COUNT(*) AS count FROM forum_directory WHERE MATCH(keywords) AGAINST('+$keywords' IN BOOLEAN MODE)");
$perpage = 2;
$minlimit = intval(($pagenumber - 1) * $perpage + 1);
$maxlimit = intval($pagenumber * $perpage);
if ($maxlimit > $itemcount['count'])
{
$maxlimit = $itemcount['count'];
if ($minlimit > $itemcount['count'])
{
$minlimit = $itemcount['count'] - $perpage;
}
}
if ($minlimit <= 0)
{
$minlimit = 1;
}
$limit = ($minlimit - 1) . ',' . $perpage;
// $getresults = $DB_site->query("SELECT * FROM forum_directory WHERE keywords LIKE '%$keywords%'");
$getresults = $DB_site->query("SELECT * FROM forum_directory WHERE MATCH(keywords) AGAINST('+$keywords' IN BOOLEAN MODE) LIMIT $limit");
$pagenav = construct_page_nav($itemcount['count'], 'searchalien.php?s=' . $keywords .'');
if (mysql_num_rows($getresults) > 0)
while($results = $DB_site->fetch_array($getresults))
{
eval('$searchresults .= "' . fetch_template('forum_searchbit') . '";');
} else {
eval('$searchresults .= "' . fetch_template('forum_nodata') . '";');
}
// Fetch ForumAlien Index Template
eval('print_output("' . fetch_template('forum_searchindex') . '");');
Can you nudge me in the right direction? This is a search on a database, as you can probably see, so I have to get the results displayed on the search in addition to limiting the results per page and showing new results which a new page is clicked.
Any help you can provide is VERY much appreciate!
AlienSector
01-18-2005, 06:52 PM
Just noticed that while it displays the correct number of pages in the navbar, it does not say page 1 of 2, rather it says Page of 2 then 1, 2.
I am not sure what is wrong, though I have something wrong else it'd be working ;).
Brian
01-18-2005, 07:10 PM
IIRC, you need to add $pagenumber = intval($page); somewhere before the construct_page_nav() function.
AlienSector
01-18-2005, 08:18 PM
Ok, with that I show a Page 0 of 2 when it should be 1 and the pagination still does not work when clicking on the page numbers. Still shows full results.
I know this is not really an area you normally assist with since you have a huge workload with your own scripts, though if you can help me get this working, I'd greatly appreciate it; I've been it at it for days.
AlienSector
01-19-2005, 06:39 PM
Any other ideas, Brian? Again, the help is much appreciated, I just wish I could get it moving correctly and displaying the correct data.
Brian
01-20-2005, 10:24 AM
$pagenumber = intval($page);
if (!isset($pagenumber))
{
$pagenumber = 1;
}
Try adding that somewhere near the top of that code.
led_belly
12-15-2005, 06:56 PM
This has changed greatly in the current version of vbulletin. Have a look at the following proto-code and notice that construct_page_nav() now requires more arguments and that sanitize_pageresults() is available to produce default values:
// pagination limits
function paging_limit($count, $page, $perpage)
{
$minlimit = intval(($page - 1) * $perpage + 1);
$maxlimit = intval($page * $perpage);
if ($maxlimit > $count)
{
$maxlimit = $count;
if ($minlimit > $count)
{
$minlimit = $count - $perpage;
}
}
if ($minlimit <= 0)
{
$minlimit = 1;
}
$limit = ($minlimit - 1) . ',' . $perpage;
return $limit;
}
$page = $_REQUEST['page'];
$perpage = $_REQUEST['ppage'];
// get deal data
if (empty($_REQUEST['sort']) || $_REQUEST['sort'] == 'all') {
// show all
$dealcountq = $db->query_read("SELECT count(*) AS count FROM ga_deals");
$dealcount = $db->fetch_array($dealcountq);
if ($dealcount['count'] >= 1) {
sanitize_pageresults($dealcount['count'], $page, $perpage);
$limit = paging_limit($dealcount['count'], $page, $perpage);
$deals = $db->query_read("SELECT dealid, threadid FROM ga_deals LIMIT $limit");
}
/* [...] */
$pagenav = construct_page_nav($page, $perpage, $dealcount['count'], THIS_SCRIPT . '.php');
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.