If is set per_page 2 records I am getting these 2 records in page but if I click next page I am not getting remaining records in next page please anyone help me.

<?php 
@session_start();
include 'connections.php';
$button = $_POST['submit'];
$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'];
$max_pages = ceil($foundnum / $per_page);


if($start)
$start= ($start- 1) * $per_page;
else
$start=0;

   $query_with_limit = $construct . ' LIMIT ' . mysql_real_escape_string($start) .',' . mysql_real_escape_string($per_page);
    $getquery = mysql_query($query_with_limit);

while($runrows = mysql_fetch_assoc($getquery))//This while() loop will print search result
{
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?searchvalue=$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?searchvalue=$search&submit=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?searchvalue=$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?searchvalue=$search&submit=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?searchvalue=$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?searchvalue=$search&submit=0'>1</a> ";
echo " <a href='search.php?searchvalue=$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?searchvalue=$search&submit&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> ";
}  
$i = $i + $per_page;               
}

}
//close to end; only hide early pages
else
{
echo " <a href='search.php?searchvalue=$search&submit=0'>1</a> ";
echo " <a href='search.php?searchvalue=$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?searchvalue=$search&submit&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> ";  
}
$i = $i + $per_page;             
}
}
}

//next button
if (!($start >=$foundnum-$per_page))
echo " <a href='search.php?searchvalue=$search&submit&start=$next'>Next</a> ";   
}  
echo "</center>";
}
 ?>

If I click next button I am getting "search term too short".

The problem is this line $search = $_POST['searchvalue']; where the link you click did not 'post' data. What you can do is to either made the 'link' become 'post' or you can include the search terms into the url and use the 'GET' instead of 'POST'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.