i have a search script to search a database of books… some results become too long so i thought of adding a pagination but dont understand how to go about it.
below is my search script can anyone help me on how to add a functional paination?
<?php
error_reporting(E_ALL);
if (!isset($_GET['Submit'])) {
// form not submitted
}
else {
//Server Variables
$host = "localhost";
$user = "userName";
$pass = "passWord";
$db = "databaseName";
$search = empty($_GET['search'])? die ("<font size='5'font color='#FF0E0E'>ERROR: Enter Search Criteria</font>") : mysql_real_escape_string($_GET['search']);
$dropdown = empty($_GET['dropdown'])? die ("<font size='5'font color='#FF0E0E'>ERROR: Select from Dropdown</font>") : mysql_real_escape_string($_GET['dropdown']);
if(strlen($search)<=2)
echo "<font size='5'font color='#FF0E0E'><strong>Search term too short!</strong></font>";
else{
echo "<font size='5'font color='#FF0E0E'>You searched for <strong>$search</strong></font></br></br>";
//Open Connection
$connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");
//Select Database
mysql_select_db($db) or die ("Unable to connect to database");
//Create Query
$query = "SELECT DISTINCT book_id,call_no,main_title,author1,itm_type,publdate,image,subj1 FROM records WHERE $dropdown LIKE '%$search%' order by publdate" or die (mysql_error());
$result = mysql_query($query) or die (mysql_error());
$num=mysql_num_rows($result);
require_once'paginator_class.php';
mysql_close($connect);
if ($num==0)
echo "Sorry, there are no matching results for <b>$search</b>.</br></br>1.
Try more general words. </br>2. Please check your spelling";
else
{
echo "<font size='4'font color='#FF0E0E'><strong>$num</strong> results found!</font><p>";
}
$i=0;
while ($i < $num) {
$book_id=mysql_result($result,$i,"book_id");
$image=mysql_result($result,$i,"image");
$main_title=mysql_result($result,$i,"main_title");
$call_no=mysql_result($result,$i,"call_no");
$publdate=mysql_result($result,$i,"publdate");
$author1=mysql_result($result,$i,"author1");
$itm_type=mysql_result($result,$i,"itm_type");
$subj1=mysql_result($result,$i,"subj1");
echo "<table id='results'>";
echo "
<tr><td><img src='image1/$image' alt='Image not found' onError=this.onerror=null;this.src='image1/default.jpg' height='110px' width='90px'></td><td valign='top'><b><a href=details.php?id=$book_id>
<b>$main_title</b></a></b><br>
<b>By:</b> $author1<br>
<b>Call no:</b> $call_no<br>
<b>Type:</b> $itm_type<br>
<b>Year:</b> $publdate</tr><p>
<hr color='#7dd5f5' size='1'></br>
";
$i++;
}
}
}
?>