html form
// This is the dynamic drop down menu
<form action="search.php" method="post">
<?php
$select_query = "Select distinct category from books";
$select_query_run = mysql_query($select_query);
$select_query_array = mysql_fetch_array($select_query_run) ;
$cat = $select_query_array['category'];
echo "<select name='name'>";
while ($select_query_array= mysql_fetch_array($select_query_run) )
{
echo "<option value='".htmlspecialchars($select_query_array["category"])."' >".htmlspecialchars($select_query_array["category"])."</option>";
}
echo "</select>";
?>
// search field with search button
<input type="text" name="searchvalue" size="5" id="searchfield" title="searchfield" onFocus="clearText(this)"/>
<input type="submit" name="submit" value="" alt="Search" id="searchbutton" title="Search" />
</form>
SEARCH.PHP file
<?php
@session_start();
include 'connections.php';
$search = $_POST['searchvalue'];
$name = $_POST['name'];
if(strlen($search)<=1)
{
echo "Search term too short";
}
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
$construct = "SELECT * FROM books WHERE category = '$name' AND (title LIKE '%$search%' or author LIKE '%$search%')";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.";
else
{
echo "$foundnum results found !<p>";
}
$per_page = 2;
$start = $_GET['start'];// getting page number from url,
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysql_query("SELECT * FROM books WHERE $construct LIMIT $start, $per_page");
while($runrows = mysql_fetch_assoc($run)) // This while loop will prints search reasults,
{
echo '<div class="news_box">
<a href="#">';
if($runrows ['cover_page_img']=="")
{
echo '<img class="news_image" src="'.INDEX_URL.'images/book_open.jpg" alt="image" width="90" height="90"/>';
}
else{
echo '<img class="news_image" src="'.INDEX_URL.'images/BookCoverImgs/'.$row['cover_page_img'].'" alt="image" width="90" height="90"/>';
}
echo '
</a>
<h3><a href="#">'.$runrows ['title'].'</a></h3>
<p> '.substr($runrows ['edition'],0,150).'.......</p>
<div class="more float_r"><a href="#">Read more</a></div>
<div class="cleaner"></div>
</div>';
}
$prev = $start - $per_page;
$next = $start + $per_page;
$adjacents = 3;
$last = $max_pages - 1;
if($max_pages > 1)
{
//previous button
if (!($start<=0))
echo " <a href='search.php?search=$search&submit&start=$prev'>Prev</a> ";
//pages
if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$i = 0;
for ($counter = 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if(($start/$per_page) < 1 + ($adjacents * 2))
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
{
echo " <a href='search.php?search=$search&submit=0'>1</a> ";
echo " <a href='search.php?search=$search&submit&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//close to end; only hide early pages
else
{
echo " <a href='search.php?search=$search&submit=0'>1</a> ";
echo " <a href='search.php?search=$search&submit&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
}
//next button
if (!($start >=$foundnum-$per_page))
echo " <a href='search.php?search=$search&submit=$next'>Next</a> ";
}
echo "</center>";
}
I AM GETTING SEARCH RESUTLS SUCCESSFULLY, BUT I WANT TO PRINT ONLY TWO RESULTS PER PAGE MY PROBLEM IS ITS PRINTING ALL RESULTS IN ONE PAGE BUT I AM GETTING PAGINATION RESULTS (LIKE "1 2 NEXT") UNDER THE PAGE, WHY IS THIS HAPPINING PLEASE ANYONE HELP ME BY ANALYSING MY CODE..