Имам 22 записа в базата данни, направил съм скрипта да ми вади по 20 и по този начин трябва да имам 2 страници, обаче имам само 1
Код:
/* Set How many results to display per page */
include "connect.php";
$db_conn = mysql_connect("$host", "$dbusername", "$dbpassword")
or die("unable to connect to the database");
mysql_select_db("$db", $db_conn) or die("unable to select the database");
$pp = "20";
/* Select the table that you want to view, you can add things like WHERE something='something' */
$table = "users";
$total = mysql_result(mysql_query("SELECT COUNT(id) FROM $table order by tochki desc"),0);
$numofpages = $total / $pp;
if (!isset($_GET['page'])) {
$page = 1;
}
else {
$page = $_GET['page'];
}
$limitvalue = $page * $pp - ($pp);
/* Display the rows */
$chars="SET CHARACTER SET cp1251";mysql_query($chars);
$query = "SELECT* FROM $table order by tochki desc LIMIT $limitvalue, $pp";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
echo '
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td align="center" background="./images/brick.gif" width="25%"><font face="Trebuchet MS" style="font-size: 10pt"><a href="details.php?uname='.$r[username].'">'.$r[username].'</a></font></td>
<td align="center" background="./images/brick.gif" width="20%"><font face="Trebuchet MS" style="font-size: 10pt">'.$r[name].'</font></td>
<td align="center" background="./images/brick.gif" width="20%"><font face="Trebuchet MS" style="font-size: 10pt">'.$r[mahala].'</font></td>
<td align="center" background="./images/brick.gif" width="17%"><font face="Trebuchet MS" style="font-size: 10pt">'.$r[banda].'</font></td>
<td align="center" background="./images/brick.gif" width="10%"><font face="Trebuchet MS" style="font-size: 10pt">'.$r[tochki].'</font></td>
<td align="center" background="./images/brick.gif" width="8%"><font face="Trebuchet MS" style="font-size: 10pt"><a href="./messages.php?to='.$r[username].'" title="Изпрати съобщение до играча!"><img border="0" src="./images/m.gif"></a> <a href="./friends.php?user='.$r[username].'" title="Добави в приятели!"><img border="0" src="./images/b.gif"></a></font></td>
</tr>
</table>
';
}
echo "<center>";
echo "<div>";
function per_page($link, $offset) {
global $numofpages, $page;
$numofpages = round($numofpages);
$pagesstart = round($page-$offset);
$pagesend = round($page+$offset);
if ($page != "1" && round($numofpages) != "0") {
echo str_replace("%page", round($page-1), ' <a href="'.$link.'">«««</a> '); //or <font face="Trebuchet MS">«</font>
}
for($i = 1; $i <= $numofpages; $i++) {
if ($pagesstart <= $i && $pagesend >= $i) {
if ($i == $page) {
echo "<b>$i</b> ";
}
else {
echo str_replace("%page", "$i", '<a href="'.$link.'">'.$i.'</a> ');
}
}
}
if (round($numofpages) == "0") {
echo "[$i]";
}
if ($page != round($numofpages) && round($numofpages) != "0") {
echo str_replace("%page", round($page+1), '<a href="'.$link.'">»»»</a>'); //or <font face="Trebuchet MS">»</font>
echo "</div>";
}
}
/* Display the pages down the bottom */
echo '<br>';
echo 'Общо страници: '.round($numofpages).'<br>';
$stranica=per_page("?page=%page", "5");
echo $stranica;
echo "</center>";