Jump to content

Recommended Posts

set the number of rows that you want on each page, and then figure it out: something like this:

this is a basic one i use



$page_num = $_GET['page'];
if(empty($page_num))
{
$page_num = 1;
}
$ppp = 20; //posts per page
$min_ppp = ($ppp*$page_num)-$ppp;
$query = mysql_query("SELECT * FROM users") or die(mysql_error());
$num_rows = mysql_num_rows($query);
$query = mysql_query("SELECT * FROM users ORDER BY
level desc LIMIT $min_ppp, $ppp") or die(mysql_error());
$rows = mysql_num_rows($query);
$pages = ceil($num_rows/$ppp);

while($row = mysql_fetch_array($query))
{
$id= $row['ID'];
$name = $row['display_name'];
$level= $row['level'];
$gold = $row['gold'];
        $alive = $row['hp'];
  if($alive >= 1)
{
$alive2 = YES;
}
else
{
$alive2 = NO;
}

$attack = Attack;

$hp=$row['hp'];
$hp1=$row['max_hp'];
echo "<tr><td><font color=#ffffff>$id</font></td><td>";


echo"

<td><font color=#FFFFFF>$level</font></td><td><font color=#FFFFFF>$gold</font></td><td><font color=#FFFFFF>$alive2</font></td><td><font color=#FFFFFF>$hp/$hp1</font></td><td><a href =donkeyattack.php?ID=$id><font color=#FFFFFF>$attack</font></a></td></tr>";
}
echo ' </table>';
if($page_num == 1)
{
echo "Prev ";
} else
{
	$prev_page = $page_num-1;
	echo "<a href=\"{$PHP_SELF}?page={$prev_page}\">Prev</a>";
}
for($i = 1; $i <= $pages; $i++)
{
if($i == 1)
{
	echo " ";
}
if($i == $page_num)
{
	echo $i;
} else
	{
		echo "<a href=\"{$PHP_SELF}?page={$i}\">{$i}</a>";
	}
if($i != $pages)
{
	echo ", ";
} else
	{
		echo " ";
	}
}
if($page_num == $pages)
{
echo "Next";
} else
{
	$next_page = $page_num+1;
	echo "<a href=\"{$PHP_SELF}?page={$next_page}\">Next</a><br><br><BR>";
}

Link to comment
https://forums.phpfreaks.com/topic/88783-pagination-problem/#findComment-454739
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.