I have a search text box., if i search any terms for ex: PHP, html it will display a results .
now what i need is to display with a pagination pages like 1 2 3 4 5 like that
Im wasting 3days on it i tried myself a lot but no use i dono were i going wrong
no errors are coming no next page is going displays record of first 2 results
need to fetch next results on next page means page2 , 3 like that end of the result says last page. kindly help me on it .. my code is below
<?php
require('../connect.php');
$rec_limit = 2;
if (isset($_GET['search']))
{
$searchtext= $_GET['searchtext'];
}
$sql = "SELECT * from jobpost WHERE jobtitle LIKE '%$searchtext%' LIMIT 2";
mysqli_select_db($con, 'login');
$result= mysqli_query($con, $sql);
if(!$result)
{
echo "error";
}
if(mysqli_num_rows($result) >0){
echo "Your Search Term : $searchtext ";
echo"<br>";
while($row = $result->fetch_assoc())
{
echo "<table>";
echo "<tr> <td>Job Title:</td> <td>{$row['jobtitle']} </td>
</tr>".
"<tr> <td>Job Description: </td> <td>
{$row['jobdescription']}</td> </tr> ".
"<br>";
echo "</table>";
}
}
else{
echo "Your Search Term : $searchtext ";
echo "<br>";
echo "no results found";
}
// pagination
$row = mysqli_fetch_array($result, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$data = mysqli_query($con, "SELECT * FROM jobpost WHERE jobtitle LIKE
'%$searchtext%' LIMIT $offset, $rec_limit") or die(mysqli_error());
if(mysqli_num_rows($data) >0){
while($row = mysqli_fetch_array($data))
{
/*echo "<table>";
echo "<tr > <td>Job Title:</td> <td>{$row['jobtitle']} </td>
</tr>".
"<tr > <td>Job Description: </td> <td>
{$row['jobdescription']}</td> </tr> ".
"<br>";
echo "</table>"; */
}
}
else{
echo"<a href='search.php?searchtext=$searchtext&search=search'>No images
available click here for Home </a>";
}
if( $page > 0 )
{
$last = $page - 2;
echo "<br>";
echo "<a href=\"search.php?searchtext=$searchtext&search=search=$last\"
>Last 2 Records</a> |";
echo "<a href=\"search.php?searchtext=$searchtext&search=search=$page\"
>Next 2 Records</a>";
}
else if( $page == 0 )
{
echo "<br>";
echo "<a href=\"search.php?searchtext=$searchtext&search=search=$page\"
>1</a>";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<br>";
echo "<a href=\"search.php?searchtext=$searchtext&search=search=$last\"
>2</a>";
}
mysqli_close($con);
?>
kindly help me..
i just want to search any input in a text box and display it in a pagination its my need.