Since I’m not utilizing any framework, I don’t need to use any ready-made pagination library and therefore determined to jot down my very own very simple, easiest php pagination library.
Immediately I’m going to share that library (right here its not a library/class however two easy php operate).
To indicate massive numbers of information into pagination you require offset, and vary. Other than that you simply want a web page quantity collection on which consumer click on and cargo the required web page information.
I’ve created two capabilities, first to get knowledge from database desk utilizing offset, and web page no. Second, to generate web page navigation checklist for consumer.
Following operate used t get information from database desk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
operate getPageData(){
$per_page = 20;
if($_GET) { $web page=$_GET[‘web page’];}
else {$web page = 1;}
$begin = ($web page–1)*$per_page;
$sql = “SELECT * FROM staff ORDER BY emp_no LIMIT $begin, $per_page”;
$end result = mysql_query($sql);
$information = array();
whereas($row = mysql_fetch_array($end result)){
extract($row);
$information[] = array(“emp_no” => $emp_no,
“birth_date” => $birth_date,
“first_name” => $first_name,
“last_name” => $last_name,
“gender” => $gender,
“hire_date” => $hire_date);
}//whereas
return $information;
}
|
And following operate is used to generate web page navigation checklist.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
operate generatePagination(){
$per_page = 20;
//Calculating no of pages
$sql = “SELECT * FROM staff”;
$end result = mysql_query($sql);
$rely = mysql_num_rows($end result);
$pages = ceil($rely/$per_page);
$pageno = “
for($i=1; $i<=$pages; $i++){
}
$pageno .= “
“ ;return $pageno;
}
|
Later I used jquery to delete the document from desk on the fly. Following is a jquery code.
1
2
3
4
5
6
7
8
|
$(doc).prepared(operate() {
$(“img#delete”).click on(operate() {
$(this).closest(“tr”).css(“background-color”,“#FF3700”);
$(this).closest(“tr”).fadeOut(400, operate(){
$(this).take away();
});
});
});
|
The ultimate Output will seem like under.
Supply techzoo.org