Jump to content

Another paging -issue


Hulio

Recommended Posts

Here's another question considering my paging -system:

How could I make the script work like it wouldn't show all the pagenumbers at the same time. I mean if there's like a hundred of pages it would do it more likely this way:

<[1] 2 3 4 5...Next > (Showing the first page)

or

< Prev ...3 4 [5] 6 7...Next > (Showing the page #5)

[code]
<?php

include("MySQL.php");

$page_url = "Guestbook.php";

mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_selectdb($mysql_db);

class Pager
{
function getPagerData($numHits, $limit, $page)
{
$numHits = (int) $numHits;
$limit = max((int) $limit, 1);
$page = (int) $page;
$numPages = ceil($numHits / $limit);

$page = max($page, 1);
$page = min($page, $numPages);

$offset = ($page - 1) * $limit;

$ret = new stdClass;

$ret->offset = $offset;
$ret->limit = $limit;
$ret->numPages = $numPages;
$ret->Page = $page;

return $ret;
}
}

$page = $_GET['Page'];
$limit = 5;
$result = mysql_query("SELECT count(*) FROM Guestbook");
$total = mysql_result($result, 0, 0);

$pager = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->Page;

$query = "SELECT * FROM Guestbook ORDER BY Id DESC LIMIT $offset, $limit";
$result = mysql_query($query);

echo "<div align=\"center\">";
if ($page == 1)
echo "";
else
echo "<font class=\"Basic\"><a href=\"$page_url?Page=" . ($page - 1) . "\">&laquo; Prev</a></font>";

for ($i = 1; $i <= $pager->numPages; $i++) {
if ($i == $pager->Page)
echo "<font class=\"Basic\">Page $i</font>";
else
echo "<font class=\"Basic\">&nbsp;<a href=\"$page_url?Page=$i\">$i</a>&nbsp;</font>";
}

if ($page == $pager->numPages)
echo "";
else
echo "<font class=\"Basic\"><a href=\"$page_url?Page=" . ($page + 1) . "\">Next &raquo;</a></font>";
echo "</div>";

// Content begins //

for($ii = 0; $ii < mysql_numrows($result); $ii++) {
echo "<div class=\"H1\">";
echo mysql_result($result,$ii,"Topic");
echo "</div>";
echo "<p class=\"Basic\">";
echo wordwrap(nl2br(mysql_result($result,$ii,"Txt")), 60, "\n", 1);
echo "</p>";
echo "<p class=\"Sender\">";
echo mysql_result($result,$ii,"Sender");
echo " - ";
echo mysql_result($result,$ii,"Time");
echo "</p>";
}

// Content ends //

mysql_close();

?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/29297-another-paging-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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