Guys and Gals…I need help…my pagination with search box feature works except for the fact that when I click next it just refreshes the page and it doesnt show the next set of results…please help…
Code Follows:
<?php // Get the search variable from URL
if(!isset($_GET['q']))
die("Search Query not found");
$var = $_GET['q'];
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == ""){
echo "<p>Please enter a search…</p>";
exit;
}
// check for a search parameter
if (!isset($var)){
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("inventorymanage.db.7995982.hostedresource.com","inventorymanage","Barstow!!11");
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("inventorymanage") or die("Unable to select database");
// Build SQL Query
$query = "select * from invsearch where item_name like \"%$trimmed%\" order by item_name";
// EDIT HERE and specify your table and field names for the SQL query
$numresults= mysql_query($query);
$numrows= mysql_num_rows($numresults);
// next determine if s has been passed to script, if not use ZERO (0) to Limit the output
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
echo "<p align='center'>You searched for: ". $var ." </p>";
// begin to show results set
echo "<p align='center'>Results: </p>";
$count = 1 + $s ;
// now you can display the results returned
echo "<table border='2' cellpadding='0' align='center'>";
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td width='500px'>";
echo "<p style=margin:0px><font color='black' size='5px'>" . $row['item_name'] . "</font></p>";
echo "<p style=margin:0px><font color='black' size='3px'>" . $row['system'] . "</font></p>";
echo "<p style=margin:0px><font color='black' size='2px'>Item Number: " . $row['Item_num'] . "</font></p>";
echo "</td>";
echo "<td><font color='red' size='3px'>" . $row['price'] . "</font></p";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<p align='center'>";
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
$PHP_SELF = $_SERVER['search.php'];
// next we need to do the links to other results
if ($s>=1) {
// bypass PREV link if s is 0
$prevs=($s-$limit);
echo " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<Prev 10</a> ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo "<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
}
echo "<p align='center'>Showing results $b to $a of $numrows</p>";
echo "</P>";
?>