: This article mainly introduces the paging implementation of php --- mysql + ajax unordered list (ulli). If you are interested in PHP tutorials, refer to it. (The front-end displays the news list)
Note: The css implementation in the following code is not included and can be implemented by yourself. Obtain the data in the database through the callback function success of ajax, and then output the data to php through js to dynamically display the data. For memo.
Code implementation
pages.js
Var curPage = 1; // The current page number var total, pageSize, totalPage; // Get the data functiongetData (page) {$. ajax ({type: 'post', url: 'Page. php ', data: {'pagenum': page-1}, Ype: 'json', beforeSend: function () {$ ("# list ul "). append ("Loading...") ;}, Success: function (json) {$ (" # list ul "). empty (); total = json. total; // total number of records pageSize = json. pageSize; // Number of Entries displayed per page curPage = page; // totalPage = json on the current page. totalPage; // The total number of pages var li = ""; var list = json. list; $. each (list, function (index, array) {// traverses the json data column if (array ['title']. length> 28) {var title_sub = array ['title']. substring (); // Obtain the substring. } Elsevar title_sub = array ['title']; if (0 = index & 1 = curPage) li ++ ="+ Array ['content'] + "\" style = \ "color: red; font-weight: 900; \ "target = \" myIframe \ "title = \" "+ array ['title'] +" \ ">" + title_sub +""+ Array ['Date'] +"
"; Elseif (1 = index & 1 = curPage) li + ="+ Array ['content'] + "\" style = \ "color: Darkorange; font-weight: 700; \ "target = \" myIframe \ "title = \" "+ array ['title'] +" \ ">" + title_sub +""+ Array ['Date'] +"
"; Elseif (2 = index & 1 = curPage) li ++ ="+ Array ['content'] + "\" style = \ "color: Greenyellow; font-weight: 500 ;; \ "target = \" myIframe \ "title = \" "+ array ['title'] +" \ ">" + title_sub +""+ Array ['Date'] +"
"; Else li + ="+ Array ['content'] + "\" target = \ "myIframe \" title = \ "" + array ['title'] + "\"> "+ title_sub +""+ Array ['Date'] +"
";}); $ (" # List ul "). append (li) ;}, complete: function () {// Generate the pagination bar getPageBar () ;}, error: function () {alert ("data loading failed") ;}}) ;}// obtain the pagination bar functiongetPageBar () {// The page number is greater than the maximum page number. if (curPage> totalPage) curPage = totalPage; // the page number is smaller than 1if (curPage <1) curPage = 1; pageStr = "total" + total + "bar" + curPage + "/" + totalPage + ""; // if it is the first page if (curPage = 1) {pageStr + = "homepage previous page";} else {pageStr + = "homepage + (curPage-1) + "'> Previous Page";} // if the last page is if (curPage> = totalPage) {pageStr + = "next page ";} else {pageStr + = "+ (parseInt (curPage) + 1) +" '> Next Page + totalPage + "'> last page ";} $ ("# pagecount" ).html (pageStr) ;}$ (function () {getData (1); $ ("# pagecount span "). live ('click', function () {var rel = $ (this ). attr ("rel"); if (rel) {getData (rel );}});});
page.php
$ Row ['id'], 'title' => $ row ['title'], 'content' => $ row ['content'], 'date' => date ("Y-m-d", $ row ['Date']);} echojson_encode ($ arr);?>
news_manager.php
Be sure to include it in the js file.
...
...
Copyright Disclaimer: This article is an article [original] by the blogger. it can be reproduced without the permission of the blogger. it indicates the source of the blog: [http://blog.csdn.net/FreeApe]
The above introduces the paging implementation of php --- mysql + ajax unordered list (ul li), including some content, and hopes to help friends who are interested in PHP tutorials.