Hi There,
I apologize for this as I'm not a "Expert" in PHP/MYSQL i have a decent understanding and can do most certain things however. I am new to "paging" systems and am looking for help with the following code.
The Paging system all works good and well however when I click "Page 2" it shows no results, so I'm assuming it's lost the Database somewhere along the lines.
Basically, at this stage someone will "Search" for something it will go to domain.com?page=search&number=1 which will display the first 5 entries of the search they should be able to click next which go to domain.com?page=search&number=2 which will display the next 5 however as soon as you click "next page" it will show an empty page... any idea as to why? I will provide the code below.
$page = $_GET['page'];
// GET PAGE SEARCH OR CATEGORY or ALL
if ($page == "search") {
$pages=$_GET['number']; //Get the current page
$limit=5;
$qresult = mysql_query("SELECT * FROM products"); // Let's get the query
$nrResults=mysql_num_rows($qresult); // Count the results
if (($nrResults%$limit)<>0) {
$pmax=floor($nrResults/$limit)+1; // Divide to total result by the number of query you want
// to display per page($limit) and create a Max page
} else {
$pmax=floor($nrResults/$limit);
}
echo "Detected Search continuing";
// If SEARCH Then
$var = $_POST['q'] ; // get the query for the search engine (if applicable)
$trimmed = trim($var); //trim whitespace from the stored variablE
$wsearch = $_POST['type'];
if ($wsearch == "Books") {
// DISPLAY NORMAL BOOKS BULL****
if ($trimmed == "") {
echo "<p>Please enter something to search</p>";
exit;
}
echo $trimmed;
$result = mysql_query("SELECT * FROM `products` WHERE `name` LIKE '%$trimmed%' ORDER BY `id` LIMIT ".(($_GET["number"]-1)*$limit).", $limit") or die(mysql_error());
$count = mysql_numrows($result);
$numrows=mysql_num_rows($result);
if ($numrows == 0 ) { echo "<p style='font-weight: bold'>Sorry, no results were found for your search term $trimmed</p>"; exit; }
// get results
if($numrows > 1){ $return = "results";}
else{ $return = "result"; }
// display what the person searched for
echo "<p>Your search for " . $var . "" returned $numrows $return.</p>";
// begin to show results set
$count = 1 + $s ;
while($row = mysql_fetch_array($result)) {
$name = $row['name'];
$desc = $row['description'];
$bookcover = $row['bookcover'];
$price = $row['price'];
$idx = $row['id'];
$insidebook = $row['insidebook'];
$category = $row['category'];
$count++ ;
?>
// Product List etc.
<? } // END LOOP
?>
<div class="navigation">
<?
if($pages > 1) {
$prevp="<a href='http://mysite.com.au/books.php?page=search&number=".($pages-1)."' title='Previous Page'>Previous Page</a>"; } else {echo "";}
echo $prevp;
$pid=1;
while ($pid<=$pmax) {
$paging= "<a href='http://mysite.com.au/books.php?page=search&number=$pid' title='Page $pid of $pmax'> $pid</a>";
$newpaging=str_replace("<a href='http://mysite.com.au/books.php?page=search&number=$pages' title='Page $pages of $pmax'> $pages</a>", "<span>$pages</span>", $paging);
echo $newpaging;
$pid++; // create pages until reach the result
}
if($pages < $pmax) {
$nextp="<a href='http://mysite.com.au/books.php?page=search&number=".($pages+1)."' title='Next Page'>Next Page</a>"; } else {echo "";}
echo $nextp;
echo "<a href='http://mysite.com.au/books.php?page=search&number=$pmax' title='Last Page'>Last Page</a>";
}
?>