Last week at work, I encountered the code to process a section of pagination! It used to be written very skilled, may be lazy too long! It's almost forgotten.
Some knowledge is too long do not have to forget quickly ah! So it is important to review the previous knowledge often. So specially tidy out the pagination code!
The effect is as above picture; In the publishing box click Pop-up A box, first to determine whether the user is logged in, no login on the pop-up login box, has been logged on the pop-up input box, input message content, name and mobile phone number.
When you enter a good content will be shown below the content of your message, the top three for the user's latest message sorting, from the fourth from the number of praise to order.
<!--view layer--> <?php $pageIndex = isset ($_get[' P '])? $_get[' P ']:0;
echo "<script type=\" text/javascript\ ">var pageindex=". $pageIndex. "</script>";
?> <script type= "Text/javascript" src= "/jquery.js" ></script> <script type= "Text/javascript" >
function Loadmore () {pageindex = pageindex | | 0;
$.ajax ({url: ' http://www.*****.com/****/wishingwall?pageindex= ' +pageindex+ ' &callback=? '), Type: ' Get ', DataType: ' Jsonp ', success:function (d) {if (D.code = = 200
{if (D.font = = ") {return;
}else{var _html = ';
if (pageindex = = 0) {var _len=0;
if (d.font.length>3) { _len=4;
}else{_len=d.font.length;
for (var j = 0; j<_len; j + +) {var _d = D.font; _html + = ' <div class= ' wallcenter ><div class= ' items ' ><div class= ' style ' +
Random (1, 5) + ' > '; _html + = ' <div class= ' content ' > ' +_d[j].content + ' </div><span class= ' Jianjue
class= "Author" >; _html + + <span class= "zanimg" style= "Cursor:pointer" ></span><span class= "username" > ' +_d[j].
Username + ' </span> '; _html + + <span class= "Zancolor" > (<span id= "' +_d[j].id+ '" "class=" Praisenumer ' +_d[j].id+ ' "> ' +_d[j '). Praisenumer + ' </span> praise ' </span></p></div></div></div> ';
} if (D.data!= ') {var _len=0;
if (d.data.length>5 && pageindex==0) {
_len=5;
}else{_len=8;
for (var j = 0; j<_len; j + +) {var _s = D.data; _html + = ' <div class= ' wallcenter ><div class= ' items ' ><div class= ' style ' +
Random (1, 5) + ' > '; _html + = ' <div class= ' content ' > ' +_s[j].content + ' </div><span class= ' Jianjue
class= "Author" >; _html = ' <span class= ' zanimg "style=" cursor:pOinter "></span><span class=" username "> ' +_s[j].username + ' </span>"; _html + + <span class= "Zancolor" > <span id= "' +_s[j].id+ '" class= "Praisenumer ' +_s[j].id+ '" > ' +_s[j].prais
Enumer + ' </span> praise ' </span></p></div></div></div> ';
}
} $ (". Wallwrap"). Text ('); <!--write the message to--> $ (". Wallwrap"). HTML (_html). Masonry ({itemselector: '. wallcent
Er '});
var numberthis = parseint (d.page) + 1;
Thispage (D.count, numberthis);
$ (". Zanimg"). each (function (index, elm) {var $elm = $ (ELM);
$elm. Click (function () { var thisid = $elm. Parent (' P '). Find (' Span.zancolor span '). attr (' id '); $.ajax ({url: ' http://www.*****.com/****/addpraisenumer/' +thisid+ '? callback
=? ', type: ' Get ', DataType: ' Jsonp ',
Success:function (d) {
if (D.code = = 200) {
$ (". Praisenumer" +thisid). Text (D.praisenumer);
else {return;
}
}
}); })
})
}}else{return;
}
}
});
function Thispage (count, curpage) {count = Count | | 1; Count = number (count); <!--definition record number--> curpage = Curpage | |
1; Curpage = number (curpage);
<!--current page--> var per = 8;
each = number (per);
var showpages = 0;
showpages = number (showpages);
var showend = 0;
ShowEnd = number (showend);
if (Count%per > 0) {<!--define the total number of pages--> var pages = (parseint (count/per) + 1);
else {var pages = parseint (count/per);
var str = ' <span class= ' loadpage ' > ' +curpage+ ' + pages + ' page </span> '; STR + + ' <span class= "totalpage" > Total ' + pages + ' page </span> ' if (curpage!= 1) {str = ' <span C lass="FirstPage" data-page= "1" ><a href= "http://*****.*****.com/thanksgiving?p=0#content" > Home page </a></ Span> '} if (CurPage-1 > 0) {str = ' <span class= ' prevpage ' data-page= ' + (curPage-1) + ' " ><a href= "http://*****.*****.com/thanksgiving?p= ' + (curPage-2) + ' #content" > Prev </a></span> '}/
/url:http://www.bianceng.cn/webkf/php/201410/45955.htm if (pages <= 5) {showpages = 1;
ShowEnd = pages;
}else if (pages-curpage >= 4) {showpages = Curpage;
ShowEnd = curpage+4;
}else if (Pages-curpage < 4) {showpages = pages-4;
ShowEnd = pages; for (var i=showpages i<=showend; i++) {if (i = = curpage) {str = ' <a class= ' Page_trig Ger page_cur "data-page=" ' +i+ ' "onclick=" javascript:; > ' + i + ' </a> '}else{str = ' <a class= ' Page_trigger "data-page=" ' +i+ ' "href=" http://***** . *****.com/thanksgiving?p= ' + (i-1) + ' #content ' > ' + i + ' </a> '}} if (Curpage + 1 <= pages) { STR + + ' </span><span class= ' nextPage ' data-page= ' + (curpage+1) + ' ><a href= ' http://*****.*****.com/
Thanksgiving?p= ' + curpage + ' #content ' > Next </a></span> '; } if (curpage!=pages) {str = ' <span class= ' lastpage ' data-page= ' ' +pages+ ' ' ><a href= ' http://***
**.*****.com/thanksgiving?p= ' + (pages-1) + ' #content ' > Last </a></span> ';
} $ ('. Page_box '). EQ (0). html (str); </script>
<!--control layer--> <?php//Message board Display public Function Action_wishingwall () {header (' Content-t
Ype:application/x-javascript '); $callback = Isset ($_get[' callback '))?
$_get[' callback ']: ' Callback ';
$pageIndex = Arr::get ($_get, ' PageIndex ', 0);
$offset = 0;
try {$font = db::select (' id ', ' content ', ' username ', ' phone ', ' userid ', ' Usernumber ', ' Praisenumer ', ' modefied ', ' created ')->from (' tmp_*** ')->order_by (' Praisenu Mer ', ' desc ')->limit (3)->fetch_all ();
According to point praise reverse order query $list = ' (';
foreach ($font as $v) {$list. = $v [' id ']. ', ';
$list. = ' 0) ';
$pageSize = 8;
if ($pageIndex = = 0) {$pageSize = 8;
else {$offset = 8+ ($pageIndex-1) *8; $rows = db::select (' id ', ' content ', ' username ', ' phone ', ' userid ', ' Usernumber ', ' Praisenumer ', ' modefied ', ' created ')->from (' tmp_***** ')->where (' id ', db::expr (' Not in '), db::expr ($list))->order_by (' Created ', ' desc ')->limi T ($pageSize)->offset ($offset)->fetch_all (); According to the time reverse query $count = db::select (' id ')->from (' tmp_***** ')->count_a
ll (); $data = Array (' Code ' =>, ' msg ' => ' Success ', ' page ' = > $pageIndex, ' Count ' => $count, ' font ' => $font, ' data '
=> $rows,); catch (Exception $e) {$data = array (' Code ' => 3000003, ' msg ' => ' query exception ', ' Data ' => $rows,); echo $callback. '
('. Json_encode ($data). ') ';
Exit }//Dot Hop public Function Action_addpraisenumer ($id) {header (' Content-ty
Pe:application/x-javascript '); $callback = Isset ($_get[' callback '))?
$_get[' callback ']: ' Callback ';
if (Isset ($id) && $id) {//Get system only session_id $session _id = session_id ();
$result = Array (1, time ()); if (! $this->cachefilter ($session _id, "Praise", $result)) {$data = Array ('
Code ' => 3000004, ' msg ' => ' cannot be repeated within 10 seconds ',); else {db::update (' tmp_***** ')->set (Array (' Praisenumer ' => db::expr (' PRA
Isenumer+1 '))->where (' id ', ' = ', $id) ->execute (); $praisenumer = Db::select (' Praisenumer ')->from (' tmp_***** ')->where (' ID
', ' = ', $id)->fetch_one ();
$data = Array (' Code ' =>, ' Praisenumer ' => $praisenumer,
' msg ' => ' success '; } else {$data = array (' Code ' => 3000003, ' msg ' =>
' Illegal operation ',); echo $callback. '
('. Json_encode ($data). ') ';
Exit //Add Message board Public function Action_add
Wishingwall () {header (' content-type:application/x-javascript '); $callback = Isset ($_get[' callback '))?
$_get[' callback ']: ' Callback '; $content = Arr::get ($_get, ' contEnt ', ');
$username = Arr::get ($_get, ' username ', ');
$phone = Arr::get ($_get, ' phone ', '); if (empty ($content)) {$data = array (' Code ' => 3000001, ' msg ' =&G T
' Message content cannot be empty ',); else {$data = array (' content ' => $content, ' username ' => $user Name, ' phone ' => $phone, ' Praisenumer ' => 0, ' modefied ' =>
Time (), ' created ' => time ());
try {db::insert (' tmp_***** ', Array_keys ($data))->values (Array_values ($data))
->execute ();
$data = Array (' Code ' =>, ' msg ' => ' success ');
The catch (Exception $e) {$data = array ( ' Code ' => 3000002, ' msg ' => ' new failed ',); } echo $callback. '
('. Json_encode ($data). ') ';
Exit }?>
This section is PHP's paging code. Temporarily tested on the local server, the effect diagram is simple like this!