Hi There,
I apologize for this as I’m not a “Expert” in PHP/MYSQL i have a general basic understanding and can do 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.
[php]
$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 BULLSHIT
if ($trimmed == “”) {
echo “
Please enter something to search
”;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 “
Sorry, no results were found for your search term $trimmed
”; exit; }// get results
if($numrows > 1){ $return = “results”;}
else{ $return = “result”; }
// display what the person searched for
echo "
Your search for " . $var . “" returned $numrows $return.
”;// 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++ ;
?>
<!-- Book Picture -->
<div class="book">
<div class="bookpic"><img src="upload/<? echo $bookcover ?>" alt="<? echo $name ?>" width="150px" height="200px;" /><br />
<p style="color: red; font-family: Arial, Helvetica, sans-serif; font-size: medium;"> <a href="JavaScript:newPopup('http://www.mysite.com.au/viewpicture.php?id=<? echo $idx ?>&image=1');">Click for larger picture</a></p></div>
<!-- Book Description -->
<div class="bookdesc">
<!-- Book Title -->
<div style="font-weight: bold; font-size: large; text-align: left; font-family: Arial, Helvetica, sans-serif; padding-top:40px;"><? echo $name ?></div>
<!-- Book description -->
<div style="font-size:large; font-family:Arial, Helvetica, sans-serif; text-align: left;"><? echo $desc ?></div>
<!-- Book Price -->
<div style="font-size:x-large; font-weight:bold; font-family: Arial, Helvetica, sans-serif; text-align:left;">$<? echo $price ?></div>
<!-- BOOK QTY -->
<div class="qty" style="font-size: large; color:red; font-family:Arial, Helvetica, sans-serif; background-image: url(images/buy.png); width: 352px; height: 59px; margin-left: 250px; text-align:left; ">
<div style="padding-top: 15px; float:left; margin-left: 20px;">QTY: <input style="border: 0px; height: 30px; font-size: large;" size="1" /></div>
<div style="float: right; margin-top:8px; margin-right: 20px;"> <img src="images/add2cart.png" /></div>
</div>
</div>
<? } // END LOOP
?>
$newpaging=str_replace(" $pages", “$pages”, $paging);
echo $newpaging;
$pid++; // create pages until reach the result
}
if($pages < $pmax) {
$nextp=“Next Page”; } else {echo “”;}
echo $nextp;
echo “Last Page”;
}
?>
[/php]