You can adapt it to what you need most of the work is here which is fairly independent of vB:
PHP Code:
/*======================================================*\
* Taken from: https://vborg.vbsupport.ru/showthread.php?t=120540
\*======================================================*/
// Default lower and upper limit variables
$limitlower = ($pagenumber - 1) * $perpage + 1;
$limitupper = $pagenumber * $perpage;
if ($limitupper > $bannedcount['bannedcount'])
{
// Too many for upper limit
$limitupper = $bannedcount['bannedcount'];
if ($limitlower > $bannedcount['bannedcount'])
{
// Too many for lower limit
$limitlower = $bannedcount['bannedcount'] - $perpage;
}
}
if ($limitlower <= 0)
{
// Can't have negative or null lower limit
$limitlower = 1;
}
$pagenumber - Current page your on
$perpage - Number of X's to display on each page
$bannedcount['bannedcount'] - The number of the total X's