Forum Moderators: coopster
I have a lot of result when I call my sql query, so the pagination I wrote before was looking way to heavy (it was like having page numbers from page 1 to page 10000 in the bottom!) and naturally I wanted something more appropriate. Digg style pagination is what I needed, so I found a php class which does excactly that. I don't know if I am allowed to post the link, so I will try my luck as it is needed for everyone to understand my problem - the link is: <snip> . I followed the tutorial but I can get it working :(
The class itself shows up on my page footer, but does not work properly. So, I think I am getting something wrong and I do not know what.
The former pagination code which was working perfecetly (but is not suitable anymore) was this one:
<?
function div ($a, $b) {return ($a-$a%$b)/$b;}
$po_stranici = 10; // broj podataka po stranici
$vijesti = mysql_query("SELECT COUNT(MBO) AS broj FROM tusmo_baza");
$r = mysql_fetch_array($vijesti, MYSQL_ASSOC);
$broj_redova = $r['broj'];
$broj_stranica = div($broj_redova+$po_stranici-1, $po_stranici);
$stranica = @$_GET['str'];if (!isset($stranica)) $stranica = 1; else $stranica = intval($stranica);
if ($stranica < 1 ¦¦ $stranica > $broj_stranica) $stranica = 1;
$x = ($stranica - 1) * $po_stranici;
$subjekti=@mysql_query("SELECT * FROM tusmo_baza ORDER BY MBO DESC LIMIT $x, $po_stranici;");
?>
The pagination itself was working perfectly with this block of code:
<?
for ($i = 1; $i <= $broj_stranica; ++$i)
if ($i == $stranica) echo "<b>[$i]</b> ";
else echo " <a href=\"index.php?&str=$i\">$i </a>";
?>
And that was great. Than I ran into a problem described above and tried to implement the aforementioned php class but had no luck :( The pagination still shows (digg styled) but does not function at all, no next pages, no previous page no nothing.. I think I implemented it correctly but something is definitely not right. Please help.
The new block of code for pagination looks like this:
<?php
include('includes/pagination.class.php');
$p = new pagination;
$p->items(1000);
$p->limit(10);
if(isset($_GET['page'])){
$page = $_GET['page'] / 10;
$p->currentPage($page);
}else
$p->currentPage(1);
$p->show();
?>
[edited by: dreamcatcher at 2:32 pm (utc) on Aug. 17, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]
// Limit the number of pages
if ($broj_stranica >= 21) {
$broj_stranica = 20;
}
for ($i = 1; $i <= $broj_stranica; ++$i)
if ($i == $stranica) echo "<b>[$i]</b> ";
else echo " <a href=\"index.php?&str=$i\">$i </a>";
... limits $broj_stranica to 20 maximum. I've used something like this, and it works.