search page with pagination in php

<?php
ob_start();
include_once('common/header.php');
$search='';   
$search=$_REQUEST['search'];
$category=$_REQUEST['category'];
$location=$_REQUEST['location'];
?>
  <!----main-info--->
  <section id="food-category">
    <div class="block remove-top">
      <div class="container m-sis-back">
        <div class="row">
          <div class="col-lg-3">
            <div class="adds"> <a href="#"><img src="ap-img/about-stud.png" class="img-responsive"></a> </div>
          </div>
          <div class="col-lg-9">
            <div class="ml-placessec godouble golist">
              <div class="row">
  <?php
$perpage = 2;
if(isset($_GET["page"])){
$page = intval($_GET["page"]);

if($page==0)
{
    $page = 1;
}

}
else {
$page = 1;


$calc = $perpage * $page;
$start = $calc - $perpage;
// $sql1="SELECT `listing`.*, shiksha_user.phone from `listing` left join shiksha_user on listing.author_id=shiksha_user.user_id where listing.category_id='".$cat_id."' and listing.is_active_listing=1 order by listing.date_added DESC Limit $start, $perpage";

$sql1="SELECT `listing`.*, listing_category.cat_id, listing_category.categoryslug from `listing` left join listing_category on listing.category_id=listing_category.cat_id WHERE listing.listing_title LIKE '%".$search."%' AND listing_category.categoryslug LIKE '%".$category."%' AND (listing.business_address LIKE '%".$location."%' OR listing.city LIKE '%".$location."%') order by listing.date_added DESC Limit $start, $perpage";


$result1=mysqli_query($con,$sql1);
$num1=mysqli_num_rows($result1);
if($num1)
{
$i = 0;
while($row1=mysqli_fetch_assoc($result1))
{
  ?>
                <div class="col-lg-12">
                  <div class="places makelist">
                    <div class="placethumb">
                      <div class="_rEcNTLis">
                        <!---featured---->
                          <span class="corner-1"></span>
                          <span class="corner-2"></span>
                        <div class="featureds"><p><?php $featured=$row1['featured'];
if($featured==1)
{
  echo 'Featured';
}
?></p></div>
                  <img src="uploads/product/<?php echo $row1['featured_img']; ?>" alt="" class="img-responsive">
                      </div>
                   </div>
                    <div class="boxplaces clearfix">
                      <div class="placeinfos">
                        <h3><a href="<?php echo "http://" . $_SERVER['SERVER_NAME']; ?>/<?php echo $row1['categoryslug']; ?>/<?php echo $row1['listing_slug']; ?>.html"><?php echo $row1['listing_title']; ?></a></h3>
                        <span><?php echo mb_strimwidth($row1['listing_description'], 0, 50, "..."); ?></span>
                        <ul class="listmetas">
                          <li> <span class="rated"><i class="fa fa-star-half-o"></i></span> <span class="rated"><i class="fa fa-star-half-o"></i></span> <span class="rated"><i class="fa fa-star-half-o"></i></span> <span class="rated"><i class="fa fa-star-half-o"></i></span> <span class="rated"><i class="fa fa-star-half-o"></i></span> </li>
                          <li><a href="#"><i class="fa fa-chef"></i>Review</a></li>
                        </ul>
                        <div class="placedetails"> <span class="food-address"><i  class="fa fa-map-marker"></i><?php echo $row1['business_address']; ?> </span> <span class="food-mobile"><i class="fa fa-phone"></i>+91 <?php echo $row1['phone']; ?></span> </div>
                      </div>
                    </div>
                  </div>
                </div>

<?php
}
} ?>
               
              </div>
            </div>
            <div class="pagination">
             <!-- <ul>
                <li><a href="#"><i class="fa fa-angle-left"></i></a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#"><i class="fa fa-angle-right"></i></a></li>
              </ul>-->
              <?php
if(isset($page))
{

$sql="SELECT Count(*) As Total from `listing` left join listing_category on listing.category_id=listing_category.cat_id WHERE listing.listing_title LIKE '%".$search."%' AND listing_category.categoryslug LIKE '%".$category."%' AND (listing.business_address LIKE '%".$location."%' OR listing.city LIKE '%".$location."%') order by listing.date_added DESC";

$result = mysqli_query($con,$sql);
$rows = mysqli_num_rows($result);
if($rows)
{

$rs = mysqli_fetch_assoc($result);
$total = $rs["Total"];
}

$totalPages = ceil($total / $perpage);
if($page <=1 ){
echo "<span id='page_links' style='font-weight: bold;'>Prev</span>";
}
else
{
$j = $page - 1;
//echo "<span><a id='page_a_link' href='$pageURL?page=$j'>< Prev</a></span>";
echo "<span><a id='page_a_link' href='$pageURL?search=$search&category=$category&location=$location&page=$j'>< Prev</a></span>";
}
for($i=1; $i <= $totalPages; $i++)
{
if($i<>$page)
{
//echo "<span><a id='page_a_link' href='$pageURL?page=$i'>$i</a></span>";
echo "<span><a id='page_a_link' href='$pageURL?search=$search&category=$category&location=$location&page=$i'>$i</a></span>";
}
else
{
echo "<span id='page_links' style='font-weight: bold;'>$i</span>";
}
}
if($page == $totalPages )
{
echo "<span id='page_links' style='font-weight: bold;'>Next ></span>";
}
else
{
$j = $page + 1;
//echo "<span><a id='page_a_link' href='$pageURL?page=$j'>Next</a></span>";
echo "<span><a id='page_a_link' href='$pageURL?search=$search&category=$category&location=$location&page=$j'>Next</a></span>";
}
}
?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
  <!----footer--->
 <?php include_once('common/footer.php');
 ob_end_flush();
 ?>

Comments

Popular posts from this blog

dynamic create multiple ckeditor onclick event using jquery

get lat and long from city name using jquery

membership registration and login system in php