Save to database: <? Php header ("Content-type: text/html; charset = UTF-8"); // echo $ _ COOKIE ['iptag']; date_default_timezone_set ('prc '); // target website url $ aimUrl =$ _ GET ['R']; // source website $ sourceUrl =$ _ GET ['hangzhou']; // set the cookie identifier, the purpose is to prevent inaccurate statistics when a user clicks another link after a cookie is generated. $ cookieTag = $ aimUrl. $ sourceUrl; // The timestamp At Tomorrow $ nonce_time = strtotime (date ('ymd') + 1); setcookie ('iptag', $ cookieTag, $ nonce_time ); // obtain the current time for database query $ time = date ('Y-m-d'); $ Db = new MySQLi ('localhost', 'A', 'acymr ', 'www _ a_com'); if ($ mysqli-> connect_errno) {die ('database Connection Failed: '. $ mysqli-> connect_error);} $ db-> query ('set names utf8 '); $ SQL = "select * from dede_tongji where sourceUrl = '$ sourceurl' and aimUrl =' $ aimurl' and date = '$ time '"; $ res = $ db-> query ($ SQL); www.2cto.com // first, check whether the current database has the data of this link on the day. If not, create the database. Otherwise, based on the cookie value, to determine the increase of IP addresses and PVS respectively. If ($ row = $ res-> fetch_assoc () {$ pvSum = $ row ['pvsum'] + 1; if ($ _ COOKIE ['iptag'] = $ cookieTag) {$ SQL = "update dede_tongji set pvSum = '$ pvsum' where sourceUrl =' $ sourceurl' and aimUrl = '$ aimurl' and date =' $ time '"; $ db-> query ($ SQL); // otherwise, only one else {$ ipSum = $ row ['ipsum'] + 1 is added for ip and pv; $ SQL = "update dede_tongji set ipSum = '$ ipsum', pvSum =' $ pvsum' where sourceUrl = '$ sourceurl' and aimUrl =' $ aim Url 'and date =' $ time' "; $ db-> query ($ SQL );}} else {// Add a new data $ SQL = "insert into dede_tongji (sourceUrl, aimUrl, ipSum, pvSum, date) values ('$ sourceurl ', '$ aimurl',' $ Time') "; if ($ db-> query ($ SQL) {} else {$ db-> error ;}} // jump to echo using js "<script language = 'javascript '> location. href = '". $ aimUrl. "'</script>";?> Query from the database. Here we use a paging class which can be found in my Ling blog, the usage of this paging class can be well understood by combining this example with the member functions of the paging class, mainly because when the SQL statement is used for database query, the limit condition can be applied, the paging class used is: page. class. below php is the use of the front-end display data and paging classes from the database query, there are some js control date <? Php header ("Content-type: text/html; charset = UTF-8"); date_default_timezone_set ('prc'); // introduces the paging class require_once 'page. class. php '; // GET the variable $ wangzhan = emptyempty ($ _ GET ['wangzhan'])? '': $ _ GET ['hangzhou']; // If the month and date are less than 10, add 0 for database date matching $ mm =$ _ GET ['mm']; $ dd = $ _ GET ['dd']; if ($ mm <10) {$ mm = '0 '. $ mm;} if ($ dd <10) {$ dd = '0 '. $ dd;} $ date = $ _ GET ['yyyy']. '-'. $ mm. '-'. $ dd; // echo $ date; // $ time = date ('Y-m-d'); // echo 'time :'. $ time. '<br>'; // echo $ date; // exit (); // connect to the database $ db = new MySQLi ('localhost', 'A', 'acy ', 'www _ a_com '); if ($ mysqli-> connect_errno) {die ('database Connection Failed :'. $ mysqli-> Connect_error);} $ db-> query ('set names utf8'); // if the current query date is the current date, if ($ date = $ time) {// obtain the total number of items in this case. This parameter is used for paging display (this parameter is required for paging) $ SQL = "select count (*) from dede_tongji where sourceUrl = '$ wangzhan' order by date desc"; $ row = $ db-> query ($ SQL) -> fetch_row (); $ allRows = $ row [0]; // total number of entries $ pageList = new Page ($ allRows, 2, 4, array ('pre' => 'pre', 'Next' => 'Next page'); // $ res = $ db-> query ("select * from dede_tongji Where sourceUrl = '$ wangzhan' order by date desc {$ pageList-> limit ()}"); $ SQL = "select * from dede_tongji where sourceUrl = '$ wangzhan' order by date desc {$ pageList-> limit ()}"; // echo $ SQL; $ res = $ db-> query ($ SQL); $ resArr = array (); while ($ row = $ res-> fetch_assoc ()) {$ resArr [] = $ row;} $ res-> free_result ();/* echo '<pre>'; var_dump ($ resArr ); foreach ($ resArr as $ v) {echo $ v ['aimurl'];} * // pri Nt_r ($ res); // exit ();} else {// obtain the total number of records in this case, used to display $ SQL = "select count (*) by PAGE (*) from dede_tongji where sourceUrl = '$ wangzhan' and date = '$ date' "; $ row = $ db-> query ($ SQL)-> fetch_row (); $ allRows = $ row [0]; // Total number of items $ pageList = new Page ($ allRows, 2, 4, array ('pre' => 'preput ', 'Next' => 'Next page ')); $ SQL = "select * from dede_tongji where sourceUrl = '$ wangzhan' and date = '$ date' {$ pageList-> limit ()}"; // echo $ SQL; $ res = $ db-> Query ($ SQL); $ resArr = array (); while ($ row = $ res-> fetch_assoc () {$ resArr [] = $ row ;} $ res-> free_result (); // print_r ($ res); // exit () ;}?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">