Advertisement
annya

pagination page

Nov 3rd, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.96 KB | None | 0 0
  1.  <?php
  2.  session_start();
  3. include_once('db.php');
  4. //include "includes/MysqlConnect.php";
  5. //$con = MysqlConnect::getInstance();
  6. $a=$_GET['result'];
  7. $query="select plot_detailsid from plot_details where cid=17";
  8. $res    = mysqli_query($connection,$query);
  9. $count  = mysqli_fetch_array($res);
  10. $page = (int) (!isset($_REQUEST['pageId']) ? 1 :$_REQUEST['pageId']);
  11. $page = ($page == 0 ? 1 : $page);
  12. $recordsPerPage = 3;
  13. $start = ($page-1) * $recordsPerPage;
  14. $adjacents = "2";
  15.    
  16. $prev = $page - 1;
  17. $next = $page + 1;
  18. $lastpage = ceil($count/$recordsPerPage);
  19. $lpm1 = $lastpage - 1;  
  20. $pagination = "";
  21. if($lastpage > 1)
  22.     {  
  23.         $pagination .= "<div class='pagination'>";
  24.         if ($page > 1)
  25.             $pagination.= "<a href=\"#Page=".($prev)."\" onClick='changePagination(".($prev).");'>&laquo; Previous&nbsp;&nbsp;</a>";
  26.         else
  27.             $pagination.= "<span class='disabled'>&laquo; Previous&nbsp;&nbsp;</span>";  
  28.         if ($lastpage < 7 + ($adjacents * 2))
  29.         {  
  30.             for ($counter = 1; $counter <= $lastpage; $counter++)
  31.             {
  32.                 if ($counter == $page)
  33.                     $pagination.= "<span class='current'>$counter</span>";
  34.                 else
  35.                     $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";    
  36.                          
  37.             }
  38.         }
  39.         elseif($lastpage > 5 + ($adjacents * 2))
  40.         {
  41.             if($page < 1 + ($adjacents * 2))
  42.             {
  43.                 for($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
  44.                 {
  45.                     if($counter == $page)
  46.                         $pagination.= "<span class='current'>$counter</span>";
  47.                     else
  48.                         $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";    
  49.                 }
  50.                 $pagination.= "...";
  51.                 $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
  52.                 $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";  
  53.            
  54.            }
  55.            elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
  56.            {
  57.                $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
  58.                $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
  59.                $pagination.= "...";
  60.                for($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
  61.                {
  62.                    if($counter == $page)
  63.                        $pagination.= "<span class='current'>$counter</span>";
  64.                    else
  65.                        $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";    
  66.                }
  67.                $pagination.= "..";
  68.                $pagination.= "<a href=\"#Page=".($lpm1)."\" onClick='changePagination(".($lpm1).");'>$lpm1</a>";
  69.                $pagination.= "<a href=\"#Page=".($lastpage)."\" onClick='changePagination(".($lastpage).");'>$lastpage</a>";  
  70.            }
  71.            else
  72.            {
  73.                $pagination.= "<a href=\"#Page=\"1\"\" onClick='changePagination(1);'>1</a>";
  74.                $pagination.= "<a href=\"#Page=\"2\"\" onClick='changePagination(2);'>2</a>";
  75.                $pagination.= "..";
  76.                for($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
  77.                {
  78.                    if($counter == $page)
  79.                         $pagination.= "<span class='current'>$counter</span>";
  80.                    else
  81.                         $pagination.= "<a href=\"#Page=".($counter)."\" onClick='changePagination(".($counter).");'>$counter</a>";    
  82.                }
  83.            }
  84.         }
  85.         if($page < $counter - 1)
  86.             $pagination.= "<a href=\"#Page=".($next)."\" onClick='changePagination(".($next).");'>Next &raquo;</a>";
  87.         else
  88.             $pagination.= "<span class='disabled'>Next &raquo;</span>";
  89.        
  90.         $pagination.= "</div>";      
  91.     }
  92.    
  93. if(isset($_POST['pageId']) && !empty($_POST['pageId']))
  94. {
  95.     $id=$_POST['pageId'];
  96. }
  97. else
  98. {
  99.     $id='0';
  100. }
  101. $query="select * from plot_details where cid= $a
  102. limit ".mysqli_real_escape_string($connection,$start).",$recordsPerPage";
  103. //echo $query;
  104. $res    =   mysqli_query($connection,$query);
  105. $count  =   mysqli_fetch_array($res);
  106. $HTML='';
  107. ?>
  108.  
  109.   <div class="mod">
  110.            
  111.        
  112.         <div id="grid-product"> <?php if($count > 0)
  113. {
  114.     while($row=mysqli_fetch_array($res))
  115.     {
  116.         $title=$row['title'];
  117.         $content=$row['content'];
  118.         $covered_area=$row['covered_area'];
  119.         $feet=$row['feet'];
  120.         $city=$row['city'];
  121.         $locality=$row['locality'];
  122.         $imgname=$row['imgname'];
  123.         $random_id=$row['random_id'];
  124.         $price=$row['price'];
  125.         $plot_detailsid=$row['plot_detailsid'];
  126.        
  127.    
  128.  
  129. ?> <?php //foreach($sql as $row){?>
  130.             <table role="grid" style="height: auto;"> <tbody role="rowgroup">
  131.    
  132.      
  133.      
  134.             <div class="list-view featured">
  135.                
  136.                
  137.                
  138.                 <div class="img-wrapper">
  139.                     <a href="pdetail.php?result=<?php echo $plot_detailsid;?>" link="public/images/thumbs/<?php echo $imgname;?>" title="3 Photos"><img src="public/images/<?php echo $imgname;?>" border="0" class="thumb" height="100" width="100"></a>
  140.                  
  141.                    
  142.                    
  143.                    
  144.                 </div>
  145.                 <div class="details">
  146.                     <h3><a href="pdetail.php?result=<?php echo $plot_detailsid;?>" title="<?php echo $title;?>"><?php echo $title;?></a></h3>
  147.  
  148.                                                                           <?php                                          
  149.                                                    
  150.       $string=$content;                                              
  151. $string = strip_tags($string);
  152.  
  153. if (strlen($string) > 200) {
  154.  
  155.     // truncate string
  156.     $stringCut = substr($string, 0, 200);
  157.  
  158.     // make sure it ends in a word so assassinate doesn't become ass...
  159.     $string = substr($stringCut, 0, strrpos($stringCut, ' '));
  160. }
  161. ?>
  162.                        
  163.                         <?php echo $string;?> <br>
  164.                        
  165.                        
  166.                        
  167.                    
  168.                         <span>Area: </span> <?php echo $covered_area; ?>&nbsp;<?php echo $feet;?>&nbsp;&nbsp;<span>Location:  </span><?php echo $city;?> ,<?php echo $locality;?> <br>
  169.                                        
  170.                    
  171.                  
  172.                        
  173.                 </div>
  174.                
  175.                  <div class="info spacer">
  176.                     <span>Property ID :</span><?php echo $random_id;?>
  177.  
  178.                        
  179.                 <hr>
  180.                        
  181.                         <div class="call"> RS:<?php echo $price;?>  </div>
  182.        
  183.                  </div>
  184.                  
  185.                 <hr>
  186.              
  187.                         <span class="contact"><a href="#">Contact</a></span> &nbsp;
  188.                 <span class="write-review"><a href="#">Write a review</a></span> &nbsp; |
  189.                 <a href="#">More Photos</a> |
  190.                 <a href="pdetail.php?result=<?php echo $plot_detailsid;?>">View Details</a>
  191.  
  192.             </div><?php //} ?> 
  193.                 <div id="pageData"></div>
  194.             <div id="grid-product">
  195.                
  196.    
  197.      
  198.      
  199.            
  200.            
  201.    
  202.     </tbody></table></div>
  203.      
  204.         </div>
  205.         <?php
  206.         }
  207.         }
  208.         else
  209. {
  210.     $HTML='No Data Found';
  211. }
  212. echo $HTML;
  213. echo $pagination;
  214.  
  215. ?>
  216.  
  217. <script type="text/javascript">
  218. $(document).ready(function(){
  219. changePagination('0');    
  220. });
  221. function changePagination(pageId){
  222.      $(".flash").show();
  223.      $(".flash").fadeIn(400).html
  224.                 ('Loading <img src="ajax-loader.gif" />');
  225.      var dataString = 'pageId='+ pageId;
  226.      $.ajax({
  227.            type: "POST",
  228.            url: "product_list.php",
  229.            data: dataString,
  230.            cache: false,
  231.            success: function(result){
  232.            $(".flash").hide();
  233.                  $("#pageData").html(result);
  234.            }
  235.       });
  236. }
  237. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement