Hej Udviklere!
Jeg sidder og roder med pagination. Mit script er som følgende:
- <?php
- **Database stuff**
- mysql_select_db($database,$db);
-
- $tbl_name="pictures";
- $adjacents = 3;
-
-
- $query = "SELECT COUNT(*) as num FROM $tbl_name";
- $total_pages = mysql_fetch_array(mysql_query($query));
- $total_pages = $total_pages[num];
-
-
- $targetpage = "";
- $limit = 72;
- $page = $_GET['page'];
- if($page)
- $start = ($page - 1) * $limit;
- else
- $start = 0;
-
-
- $sql = "SELECT ********** FROM $tbl_name WHERE *************** ORDER BY id DESC LIMIT $start, $limit";
- $result = mysql_query($sql);
-
-
- if ($page == 0) $page = 1;
- $prev = $page - 1;
- $next = $page + 1;
- $lastpage = ceil($total_pages/$limit);
- $lpm1 = $lastpage - 1;
-
-
- $pagination = "";
- if($lastpage > 1)
- {
- $pagination .= "<div class=\"pagination\">";
- if ($page > 1)
- $pagination.= "<a href=\"$targetpage?page=$prev\"><img src=\"../img/prev.png\" /></a>";
- else
- $pagination.= "<img src=\"../img/prev_disabled.png\" />";
-
- if ($lastpage < 7 + ($adjacents * 2))
- {
- for ($counter = 1; $counter <= $lastpage; $counter++)
- {
- if ($counter == $page)
- $pagination.= "<span class=\"current\"> $counter</span>";
- else
- $pagination.= "<a href=\"$targetpage?page=$counter\"> $counter</a>";
- }
- }
- elseif($lastpage > 5 + ($adjacents * 2))
- {
- if($page < 1 + ($adjacents * 2))
- {
- for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
- {
- if ($counter == $page)
- $pagination.= "<span class=\"current\"> $counter</span>";
- else
- $pagination.= "<a href=\"$targetpage?page=$counter\"> $counter</a>";
- }
- $pagination.= "...";
- $pagination.= "<a href=\"$targetpage?page=$lpm1\"> $lpm1</a>";
- $pagination.= "<a href=\"$targetpage?page=$lastpage\"> $lastpage</a>";
- }
- elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
- {
- $pagination.= "<a href=\"$targetpage?page=1\"> 1</a>";
- $pagination.= "<a href=\"$targetpage?page=2\"> 2</a>";
- $pagination.= "...";
- for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
- {
- if ($counter == $page)
- $pagination.= "<span class=\"current\"> $counter</span>";
- else
- $pagination.= "<a href=\"$targetpage?page=$counter\"> $counter</a>";
- }
- $pagination.= "...";
- $pagination.= "<a href=\"$targetpage?page=$lpm1\"> $lpm1</a>";
- $pagination.= "<a href=\"$targetpage?page=$lastpage\"> $lastpage</a>";
- }
- else
- {
- $pagination.= "<a href=\"$targetpage?page=1\"> 1</a>";
- $pagination.= "<a href=\"$targetpage?page=2\"> 2</a>";
- $pagination.= "...";
- for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
- {
- if ($counter == $page)
- $pagination.= "<span class=\"current\"> $counter</span>";
- else
- $pagination.= "<a href=\"$targetpage?page=$counter\"> $counter</a>";
- }
- }
- }
-
- if ($page < $counter - 1)
- $pagination.= "<a href=\"$targetpage?page=$next\"><img src=\"../img/next.png\" />";
- else
- $pagination.= "<img src=\"../img/next_disabled.png\" />";
- $pagination.= "</div>\n";
- }
- ?>
Scriptet er fra en god guide, jeg fandt på Google.
Anyway, mnit spørgsmål er.
Når jeg bladrer i en side, tilføjer scriptet automatisk "?=page=2" til URL'en.
Så tænker jeg logisk, og tænker at hvis jeg nu sætter targetpage til:
- $targetpage = "category=animals";
.. ville min url blive: ?category=animals&page=2
Thing is, det virker bare ikke.
Er der nogle der har en idé om hvorfor?
På forhånd mange tak!
Med venlig hilsen,
Rai.
Indlæg senest redigeret d. 21.11.2011 22:52 af Bruger #16811