Hey Guys. I'm having a small problem with my pagination script [I did not right it, just modified it]. Basically it works great except for 1 thing, when you change the page (or go to the next one) it ignores the query and by that I mean let's say you have:
http://site.com/page.php?cat=1
That's your page, well you want to go to page Number to say:
http://site.com/page.php?cat=1&page=2
I can't get that to work because it's ignoring the address. Now I had an idea of how to fix that for like going to page # 2 but my method wouldn't work cause it would essentially keeping adding "page" to the address sooo I'm looking for help!
Here's the Code for the pagination:
PHP Code:
<?php
// What Page are we on?
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
include ('connect_avail.php');
$cats = $_GET['cat'];
// Are any categories defined?
if (empty($cats)) {
$query = "SELECT * FROM cat_ballpythons ORDER BY priority DESC";
} else {
$query = "SELECT * FROM cat_ballpythons WHERE (";
for ($i = 0; $i < count($cats); $i++) {
$cat = mysql_escape_string(strip_tags($cats[$i]));
$query .= "keywords LIKE '%$cat%' ";
if (($i+1) < count($cats)) {
$query .= "or ";
}
}
$query .= ") ORDER BY priority DESC";
}
$result = @mysql_query($query);
$query_data = @mysql_fetch_row($result);
$numrows = mysql_num_rows($result);
$rows_per_page = 2;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
// Let's make sure we're not on a page that doesn't exsist.
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
// Let's Setup our Queries shall we?
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
if (empty($cats)) {
$query = "SELECT * FROM cat_ballpythons ORDER BY priority DESC $limit";
} else {
$query = "SELECT * FROM cat_ballpythons WHERE (";
for ($i = 0; $i < count($cats); $i++) {
$cat = mysql_escape_string(strip_tags($cats[$i]));
$query .= "keywords LIKE '%$cat%' ";
if (($i+1) < count($cats)) {
$query .= "or ";
}
}
$query .= ") ORDER BY priority DESC $limit";
}
$result = mysql_query($query);
?>
Like I said that part works great, no problems here. However what I need to fix is this:
PHP Code:
<?
// Display the First Link and the Back Link
if ($pageno == 1) {
echo "<img src='template/arrow_start.gif' border='0' /> <img src='template/arrow_back.gif' border='0' />";
} else {
echo "<a href='{$_SERVER['PHP_SELF']}?pageno=1'><img src='template/arrow_start.gif' border='0' /></a>";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><img src='template/arrow_back.gif' border='0' /></a> ";
}
// Show what page we are on, and how many there is.
echo " <strong>( Page $pageno of $lastpage )</strong> ";
// Display the Next Link and the Last Link
if ($pageno == $lastpage) {
echo " <img src='template/arrow_forward.gif' border='0' /> <img src='template/arrow_last.gif' border='0' /> ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'><img src='template/arrow_forward.gif' border='0' /></a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'><img src='template/arrow_last.gif' border='0' /></a> ";
}
?>
So Basically when I'm on page "page.php?cat=1" I want the link to go to Page 2 and still keep the ?cat=1 in there or whatever else may be in there. It isn't rare for my address to be like page.php?cat=1&cat=2&cat=3 etc.