Monday, 23 January 2017

SEARCH CODE WITH PAGINATION EXAMPLE

06:22

=============================================================================
(1)create table details : 
SQL>create table  details
(id  int primary key auto_increment,
 name   varchar(200),
city     varchar(200)
);

(2)write code for search.html file:

<form action="search.php" method="get">
name <input type=text name=search>
<input type=submit name=submit value=submit>

</form>

(3)write code for search.php file:

<?php
    $search=$_GET['search'];
    mysql_connect("localhost","root","")or die("Problems...");
    mysql_select_db("ajax");

    $per_page = 2;
    $pages_query = mysql_query("SELECT COUNT('id') FROM  details where name='$search' ");
    echo $pages_query."<br>";
    $pages = ceil(mysql_result($pages_query, 0) / $per_page);
    echo $pages;
   
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
    $start = ($page - 1) * $per_page;
   
    $query = mysql_query("SELECT *  FROM details where name='$search' LIMIT $start, $per_page");
   
    while($row = mysql_fetch_assoc($query))
   
   
    {
   
   echo $row['id'];

  echo $row['name'];
echo $row['city'];


   
   
   
    }
   
    $prev = $page - 1;
    $next = $page + 1;
   
    if(!($page<=1)){
        echo "<a href='search1.php?page=$prev&search=$search'>Prev</a> ";
    }

    if($pages>=1 && $page<=$pages){
   
        for($x=1;$x<=$pages;$x++){
            echo ($x == $page) ? '<strong><a href="?page='.$x.'&search='.$search.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'&search='.$search.'">'.$x.'</a> ';
       
        }
   
    }
   
    if(!($page>=$pages)){
        echo "<a href='search1.php?page=$next&search=$search'>Next</a>";
    }
   
   

?>



Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

1 comments:

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top