Simple implementation of Ajax without refreshing pages and ajax refreshing pages
Implementation of the following code:
<! Doctype html>
The paging code found on the Internet is available for test ~
/** Created on 2011-07-28 * Author: LKK, http://lianq.net * Usage: require_once ('mypage. php '); $ result = mysql_query ("select * from mytable", $ myconn); $ total = mysql_num_rows ($ result); // pageDivide ($ total, 10); // call the paging function // database operation $ result = mysql_query ("select * from mytable limit $ sqlfirst, $ shownu", $ myconn ); while ($ row = mysql_fetch_array ($ result )){... your operation} echo $ pagecon; // output the page navigation content * // if (! Function_exists ("pageDivide") {# $ total Information # $ shownu display quantity, default 20 # $ url link to this page function pageDivide ($ total, $ shownu = 20, $ url = '') {# $ page Current page # $ sqlfirst mysql database start item # $ pagecon paging navigation content global $ page, $ sqlfirst, $ pagecon, $ _ SERVER; $ GLOBALS ["shownu"] = $ shownu; if (isset ($ _ GET ['page']) {$ page = $ _ GET ['page'];} else $ page = 1; # if $ url uses the default value, that is, null value, it is assigned to the URL of this page if (! $ Url) {$ url = $ _ SERVER ["REQUEST_URI"] ;}# URL analysis $ parse_url = parse_url ($ url ); @ $ url_query = $ parse_url ["query"]; // The question mark? After the content if ($ url_query) {$ url_query = preg_replace ("/(&?) (Page = $ page)/"," ", $ url_query); $ url = str_replace ($ parse_url [" query "], $ url_query, $ url ); if ($ url_query) {$ url. = "& page";} else $ url. = "page";} else $ url. = "? Page "; # page number calculation $ lastpg = ceil ($ total/$ shownu); // last page, total page number $ page = min ($ lastpg, $ page ); $ prepg = $ page-1; // Previous page $ nextpg = ($ page = $ lastpg? 0: $ page + 1); // next page $ sqlfirst = ($ page-1) * $ shownu; # Start pagecon navigation content $ pagecon = "show no ". ($ total? ($ Sqlfirst + 1): 0 ). "-". min ($ sqlfirst + $ shownu, $ total ). "records, total <B> $ total </B> records"; if ($ lastpg <= 1) return false; // jump out if only one page exists. // if ($ page! = 1) $ pagecon. = "<a href = '$ url = 1'> homepage </a>"; else $ pagecon. = "Homepage"; // if ($ prepg) $ pagecon. = "<a href = '$ url = $ prepg'> previous page </a>"; else $ pagecon. = "Previous Page"; // if ($ nextpg) $ pagecon. = "<a href = '$ url = $ nextpg'> next page </a>"; else $ pagecon. = "back page"; // if ($ page! = $ Lastpg) $ pagecon. = "<a href = '$ url = $ lastpg'> last page </a>"; else $ pagecon. = "last page"; if ($ page! = 1) $ pagecon. = "<a href = 'javascript: showpage (\" $ url = 1 \ ") '> homepage </a>"; else $ pagecon. = "Homepage"; if ($ prepg) $ pagecon. = "<a href = 'javascript: showpage (\" $ url = $ prepg \ ") '> previous page </a>"; else $ pagecon. = "Previous Page"; if ($ nextpg) $ pagecon. = "<a href = 'javascript: showpage (\" $ url = $ nextpg \ ") '> next page </a>"; else $ pagecon. = "back page"; if ($ page! = $ Lastpg) $ pagecon. = "<a href = 'javascript: showpage (\" $ url = $ lastpg \ ") '> last page </a>"; else $ pagecon. = "last page"; # Jump to the drop-down list and list all page numbers cyclically // $ pagecon. = "to the <select name = 'topage' size = '1' onchange = 'window. location = \ "$ url = \" + this. value '> \ n "; $ pagecon. = "to the <select name = 'topage' size = '1' onchange = 'showpage (\" $ url = \ "+ this. value) '> \ n "; for ($ I = 1; $ I <= $ lastpg; $ I ++) {if ($ I = $ page) $ pagecon. = "<option value = '$ I' selected> $ I </Option> \ n "; else $ pagecon. = "<option value = '$ I'> $ I </option> \ n" ;}$ pagecon. = "</select> page, $ lastpg page in total"; return $ page;} //} else die ('pagedivide () function with the same name already exists! ');
Below is a simple page display by myself
<? Php header ("Content-type: text/html; charset = UTF-8"); $ link = mysqli_connect ('localhost', 'root', '123', 'good '); if (! $ Link) {die ("connection error :". mysqli_connect_error ();} $ SQL = "SELECT * FROM ecs_category"; $ qry = mysqli_query ($ link, $ SQL); $ total = mysqli_num_rows ($ qry ); $ per = 10; $ page = pageDivide ($ total, $ per); $ SQL = "SELECT cat_id, cat_name FROM category limit $ sqlfirst, $ shownu "; $ result = mysqli_query ($ link, $ SQL); // $ goods = mysqli_fetch_all ($ result, MYSQLI_ASSOC); // mysqli_free_result ($ result ); echo <eof <style type = "text/css"> table {width: 500px; margin: auto; border: 1px solid black; border-collapse: collapse; text-align: center;} td {border: 1px solid black ;} </style> <table> <tr> <td> NO. </td> <td> product no. </td> <td> product type </td> </tr> eof; $ num = ($ page-1) * $ per; // foreach ($ goods as $ k => $ v) {while ($ goods = mysqli_fetch_assoc ($ result )) {echo "<tr>"; echo "<td> ". ++ $ num. "</td>"; echo "<td> $ goods [cat_id] </td>"; echo "<td> $ goods [cat_name] </td> "; echo "</tr>" ;}echo "<tr> <td colspan = '3'> $ pagecon </td> </tr> "; echo "</table> ";
The page does not refresh and the URL does not change. You can see the data interaction of the website.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.