Judul : SEARCH CODE WITH PAGINATION EXAMPLE
link : SEARCH CODE WITH PAGINATION EXAMPLE
SEARCH CODE WITH PAGINATION EXAMPLE
=============================================================================
(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>";
}
?>
(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>";
}
?>
Demikianlah Artikel SEARCH CODE WITH PAGINATION EXAMPLE
Sekianlah artikel SEARCH CODE WITH PAGINATION EXAMPLE kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel SEARCH CODE WITH PAGINATION EXAMPLE dengan alamat link https://othereffect.blogspot.com/2017/01/search-code-with-pagination-example.html
0 Response to "SEARCH CODE WITH PAGINATION EXAMPLE "
Post a Comment