Page Numbering Query - page one ok, page 2,3..not ok.
Posted: Mon Aug 24, 2009 3:26 am
Dear all
I have a strange issue here. The search form passes the data to this page. For now I am using only the $searchadv and $category variables.
If I use only the $searchadv then the pages work, with results on each page.
If I bring $category into play, page one works and it shows there are other pages, but when you click on them you see the
I have a strange issue here. The search form passes the data to this page. For now I am using only the $searchadv and $category variables.
If I use only the $searchadv then the pages work, with results on each page.
If I bring $category into play, page one works and it shows there are other pages, but when you click on them you see the
Can anyone please help.<div class='sectionhead'>Sorry, there are no results for $search.</div>
Code: Select all
<?php
$searchadv = $_POST['searchadv'];
$category = $_POST['category'];
$pricemin = $_POST['pricemin'];
$pricemax = $_POST['pricemax'];
include "dbconn.php";
echo "<div class='head'>Advanced Searching</div>";
$rowsPerPage = 5;
// by default we show first page
$pageNum = 1;
// if $_GET['pagenum'] defined, use it as page number
if(isset($_GET['pagenum']))
{
$pageNum = $_GET['pagenum'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
echo "<table width='100%' cellpadding='0' cellspacing='0' class='table'>";
$result = mysql_query ("SELECT * FROM products WHERE title LIKE '%$searchadv%' AND category = '$category' LIMIT $offset, $rowsPerPage") or die (mysql_error());
if (mysql_num_rows($result)==0) { echo "<div class='sectionhead'>Sorry, there are no results for $search.</div>"; }
else {
while ($row = mysql_fetch_object($result))
while ($row = mysql_fetch_object($result)) {
echo "
<div class='cat_prodlistbox'>
<div class='cat_producttitle'>";
$position=43; //Defines how many characters will be displayed from content field.
$postcontent = substr($row->title,0,$position);
echo "$postcontent ...</div>
<a href='index.php?page=product&menu=categ&category=$row->category&product=$row->id' title='Look at the $row->title'><img src='images/productphotos/$row->photoprimary' border='0' /></a></div
</div>
";
}}
mysql_free_result($result);
echo "</table>";
echo "<div style='clear:both' /><hr noshade size='1' color='#cccccc' />";
$query = "SELECT COUNT(id) AS numrows FROM products WHERE title LIKE '%$searchadv%' AND category = '$category'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>$page</a>";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>[Prev]</a> ";
$first = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=1\" class='bodylink'>[First Page]</a>";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$page\" class='bodylink'>[Next]</a>";
$last = " <a href=\"index.php?page=searchadvresults&menu=home&pagenum=$maxPage\" class='bodylink'>[Last Page]</a>";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo "<div class='navpages'>" . $first . $prev . $nav . $next . $last . "</div>";
mysql_close($sqlconn);
?>