Search Option |
When you using server side pagination first you must check
it out that on which page your record is exist. Like in my example I want to
search ID number “17”. And on per page I am displaying total 10 numbers of
rows/records so it means ID number “17” exist on page 2.
Copy and paste this example code which is more
understandable.
Step 1:
Create database like "tutorials" and then create table "BOOKS_TBL" with more then 10 record. below is the script of table and data.
--
-- Table structure for table `books_tbl`
--
CREATE TABLE IF NOT EXISTS `books_tbl` (
`BOOK_ID` int(11) NOT NULL AUTO_INCREMENT,
`BOOK_NAME` varchar(100) NOT NULL,
PRIMARY KEY (`BOOK_ID`),
UNIQUE KEY `BOOK_NAME` (`BOOK_NAME`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=33 ;
--
-- Dumping data for table `books_tbl`
--
INSERT INTO `books_tbl` (`BOOK_ID`, `BOOK_NAME`) VALUES
(10, 'Biology'),
(11, 'Book 1'),
(20, 'Book 10'),
(21, 'Book 11'),
(22, 'Book 12'),
(23, 'Book 13'),
(24, 'Book 14'),
(25, 'Book 15'),
(26, 'Book 16'),
(27, 'Book 17'),
(28, 'Book 18'),
(29, 'Book 19'),
(12, 'Book 2'),
(30, 'Book 20'),
(31, 'Book 21'),
(32, 'Book 22'),
(13, 'Book 3'),
(14, 'Book 4'),
(15, 'Book 5'),
(16, 'Book 6'),
(17, 'Book 7'),
(18, 'Book 8'),
(19, 'Book 9'),
(9, 'Chemistry'),
(1, 'English A'),
(2, 'English B'),
(7, 'General Science'),
(5, 'Mathematics'),
(8, 'Physics'),
(6, 'Social Studies'),
(3, 'Urdu A'),
(4, 'Urdu B');
Step 2:
create a file with the name of "pagination.php". and insert the following Code in this file.
<?php
error_reporting(0);
$num_rec_per_page=10;
$con = mysql_connect('localhost','root','');
mysql_select_db('tutorials');
if (isset($_GET["search"])) // this if is related to search option
{
$searchid = $_POST["search"]; // assig the search id which you want to search to $searchid variable.
$pageid = ceil($searchid / $num_rec_per_page); // this statement is checking that on which page this search record is exist.
header("location: pagination.php?sid=".$searchid."&page=".$pageid); // after check the page redirect the URL on that page like in my case URL will: http://localhost/tutorials/pagination.php?sid=17&page=2
} // end if of $_GET["search"]
else
{
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else
{
$page=1;
}
}
$start_from = ($page - 1) * $num_rec_per_page;
$sql = "SELECT * FROM BOOKS_TBL order by BOOK_ID LIMIT $start_from, $num_rec_per_page";
//echo $sql; exit;
$rs_result = mysql_query ($sql); //run the query
?>
<html>
<head><title>Search option in a grid Tutorial | www.developerqueries.blogspot.com</title></head>
<body>
<form id="form1" method="POST" action="pagination.php?search">
<input type="text" name="search" /><input type="submit" id="btnsearch" name="btnsearch" value="Go" />
</form>
<table>
<tr><td>ID</td><td>Name</td></tr>
<?php
while ($row = mysql_fetch_array($rs_result)) {
?>
<?php
if ($_REQUEST["sid"] == $row['BOOK_ID']) // if your search result match row will be highlighted with yellow colour.
{
echo "<tr style='background-color:yellow'>";
}
else
{
echo "<tr>";
}
?>
<td><?php echo $row['BOOK_ID']; ?></td>
<td><?php echo $row['BOOK_NAME']; ?></td>
</tr>
<?php
}
?>
</table>
<?php
$sql = "SELECT * FROM BOOKS_TBL";
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result); //count number of records
$total_pages = ceil($total_records / $num_rec_per_page);
echo "<a href='pagination.php?page=1'>".'|<'."</a> "; // Goto 1st page
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
}
echo "<a href='pagination.php?page=$total_pages'>".'>|'."</a> "; // Goto last page
?>
</body>
</html>
Thanks for sharing such a great information..Its really nice and informative.
ReplyDeletePHP Training in Chennai
This was a fantastic Blog. Really loved reading your blog post. Very informative and helpful. Guys if you if learn want to learn PHP join best php training in pune .
ReplyDeleteVery nice post here thanks for it I always like and search such topics and everything connected to them. Keep update more information..
ReplyDeleteDigital Marketing Company in Chennai
Hey Very nice Blog,Thanks For Sharing..
ReplyDeleteAsp.net training Center in Lucknow
Best Php industrial training
Embedded system training in lucknow
Best Industrial training company in lucknow
java institutes in Lucknow
superb.....blog is much interesting about search option in grid view which engaged me more.Spend a worthful time.keep updating more.
ReplyDeleteSEO Company in India
Hey Very nice Blog,Thanks For Sharing..
ReplyDeleteBest python training in lucknow
best summer training in lucknow
Asp.net training Center in Lucknow
Hello, thank you very much for this article this is really helpful to website development Gold Coast. I find it useful with my future plans. Once again, thank you very much.
ReplyDeletehttp://rent-a-website.com.au/rental-plans
This comment has been removed by the author.
ReplyDeleteThank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteAsp.Net Training in Chennai | Best Dot Net Training in Chennai
Selenium Coaching Institute in Chennai | Selenium Training Institute in Chennai
Manual Testing Training in Chennai| Testing Courses in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai | PHP Training Institute in Chennai
This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
ReplyDeleteAuthorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai
This 3rd paragraph gives clear idea for the new viewers of blogging,
ReplyDeleteAuthorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai | iphone service center in chennai
Choose from 93 Premium movie templates.
ReplyDelete.
ReplyDeleteGood blog post. I want to thank you for interesting and helpful information and I like your point of view. Thank you!- I love to read this type of material Good and attractive information I take from it.. Thank you for posting such a good article.
ReplyDeletemobile phone repair in Auburn Hills
iphone repair in Auburn Hills
cell phone repair in Auburn Hills
tablet repair in Auburn Hills
ipad repair in Auburn Hills
mobile phone repair Auburn Hills
iphone repair Auburn Hills
cell phone repair Auburn Hills
phone repair Auburn Hills
tablet repair Auburn Hills
cheap hidden cameras
ismartalarm camera
dymo label maker
Waterproof Action Camera
Coleman full size air mattress
womens cotton long johns
APPLE WATCH SERIES 3 INFORMATION
Winter Cycling Jackets For Men