MyBB Community Forums

Full Version: Problem with pagination
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In short my code works fine if nothing is set other than the page, but if the data is being sorted, it multiplies the page number by 10 for some odd reason. The various url variables are defined based off the current url. The strange thing is that the number it displays is correct, but the link is not when something is set. It correctly counts the number of pages there are.

$query = mysql_query($query);
$q2 = mysql_query($q2);
$rowcount = mysql_num_rows($q2);
$pagecount = ceil ($rowcount / 100);
$previouspage=$page - 1;
$pageloop = 1;
$currentpage = 1;
 if ($page!=1)
{
	$previous = "<a href='/members/pokedex.php?page=$previouspage" . $shinyurl . $sorturl . $staturl . $regionurl . $filterurl . "'>$previouspage</a> ";
} 
while ($pageloop<$pagecount)
{
	$nextpage=$pageloop+1;
	$url = $nextpage . $shinyurl . $sorturl . $staturl . $regionurl . $filterurl;
	$next .= "<a href='/members/pokedex.php?page=$url'>$nextpage</a> ";
	$pageloop++; 
}
Setting $query as the result object of mysql_query on what query is, is very bad practice. I'm surprised that even works, to be honest.

The reason your page count is multiplied by 10 is because you're rounding page count and then randomly dividing by 100.

Another way to determine the number of rows, or the number of results, is using COUNT(*) and listing the result object to mysql_fetch_row.