The following conditions are required for paging data:
1. The total number of pages participating in the paging "$msg _count", which can be obtained through database queries;
2. The number of bars displayed per page "$pagesize", which is defined by itself;
3. The number of pages in the current page "$page", the value is passed and received through the address bar;
4. The total number of pages "$pagecount" can be calculated from the above information, which needs to be ceil ();
"$pagecount = ceil ($msg _count/$pagesize);"
5. Database queries use the "limit" in the SQL statement to change the data:
For example:
SELECT * FROM table name where condition limit $startnum, $pagesize;
and $startnum = ($page-1) * $pagesize;
Instance:
/** * Gets the last filter condition * @param string $param _str parameter string, consisting of the parameters of the list function * @return If there is, return AR Ray (' filter ' = $filter, ' sql ' = = $sql), otherwise return false */function get_filter ($param _str = ") {$filterfile = basename ( Php_self, '. php ');//string basename (String $path [, String $suffix]) returns the file name portion of the path if the file name is in the SU Ffix end, that part will be removed as well. if ($param _str) {$filterfile. = $param _str; if (Isset ($_get[' Uselastfilter ')) && isset ($_cookie[' ecscp ' [' lastfilterfile ']) && $_cookie[' E CSCP ' [' lastfilterfile '] = = sprintf ('%x ', CRC32 ($filterfile))) {return Array (' filter ' = = Unseria Lize (UrlDecode ($_cookie[' ecscp ' [' lastfilter ']), ' sql ' = Base64_decode ($_cookie[' ECSCP '] [' Lastfiltersql ']) ); } else {return false; }}
/** * Save filter condition * @param array $filter filter condition * @param string $sql query statement * @param string $param _str parameter string, consisting of the parameters of the list function */function set_filter ($filter, $sql, $param _str = ") {$filterfile = BaseName (Php_self, '. PHP '); if ($param _str) {$filterfile. = $param _str; } setcookie (' Ecscp[lastfilterfile] ', sprintf ('%x ', CRC32 ($filterfile)), time () + 600); Setcookie (' ecscp[lastfilter] ', UrlEncode (Serialize ($filter)), time () + 600); Setcookie (' ecscp[lastfiltersql] ', Base64_encode ($sql), time () + +);}
/** * Supplier Resource management * @param bool $is _pagtion * @return array $arr */function suppliers_resource_manage ($is _pagtion=t Rue) {Global $db, $ecs; $result = Get_filter (); if ($result = = = False) {$aiax = Isset ($_get[' Is_ajax '))? $_get[' Is_ajax ']: 0; /* Filter Information */$filter [' sort_by '] = Empty ($_request[' sort_by ')? ' r.resource_id ': Trim ($_request[' sort_by '); $filter [' sort_order '] = Empty ($_request[' sort_order ')? ' DESC ': Trim ($_request[' sort_order '); $filter [' resource_id '] = Empty ($_request[' resource_id ')? ": $_request[' resource_id '); $filter [' admin_name '] = Empty ($_request[' admin_name ')? ': Trim ($_request[' admin_name '); $filter [' resource_name '] = Empty ($_request[' resource_name ')? ': Trim ($_request[' resource_name '); $filter [' admin_id '] = isset ($_request[' admin_id ')? Intval ($_request[' admin_id ']): '-1 '; $filter [' resource_type '] = Empty ($_request[' Resource_type ')? '-1 ': Intval ($_request[' ResourCe_type ']); $filter [' resource_status '] = Empty ($_request[' resource_status ')? '-1 ': Intval ($_request[' resource_status '); $filter [' resource_rank '] = Empty ($_request[' Resource_rank ')? '-1 ': Intval ($_request[' Resource_rank '); $filter [' resource_key '] = Empty ($_request[' Resource_key ')? ': Trim ($_request[' resource_key '); $filter [' menuid '] = 7; $where = ' where 1 '; /* Paging Size */$filter [' page '] = Empty ($_request[' page ') | | (Intval ($_request[' page ') <= 0)? 1:intval ($_request[' page '); if (Isset ($_request[' page_size ')) && intval ($_request[' page_size ']) > 0) {$filter [' page_size '] = intval ($_request[' page_size '); } elseif (Isset ($_cookie[' ecscp ' [' page_size ']) && intval ($_cookie[' ecscp ' [' page_size ']) > 0) { $filter [' page_size '] = intval ($_cookie[' ecscp ' [' page_size ']); } else {$filter [' page_size '] = 15; } if (!empty ($filter [' resource_id '])) {$resource _id = $filter [' resource_id '] = = 1? 0: $filte r[' resource_id ']; $where. = "and r.resource_id=". $resource _id. "'"; if ($filter [' resource_name ']) {$where. = "and r.resource_name like '%". Mysql_like_quote ($filter [' Resou Rce_name ']). " %' "; } if ($filter [' admin_id '] >-1) {$where. = "and r.admin_id = '". $filter [' admin_id ']. "' "; } if ($filter [' Resource_type '] >-1) {$where. = "and R.resource_type = '". $filter [' Resource_type ']. "'"; } if ($filter [' Resource_status '] >-1) {$where. = "and R.resource_status = '". $filter [' Resource_status ']. "'"; } if ($filter [' Resource_rank '] >-1) {$where. = "and R.resource_rank = '". $filter [' Resource_rank ']. "'"; } if ($filter [' Resource_key ']) {$where. = "and R.remark Like '% '. Mysql_like_quote ($filter [' Resource_key ']). " %' "; }/* Total number of records */$sql = "Select COUNT (r.resource_id) from". $ecs->table (' Suppliers_resource '). "As R left JOIN". $ecs->table (' Admin_user '). "As U On u.user_id = r.admin_id ". $where; $filter [' record_count '] = $db->getone ($sql); $filter [' page_count '] = $filter [' record_count '] > 0? Ceil ($filter [' record_count ']/$filter [' page_size ']): 1; /* Query */$sql = "Select r.resource_id, U.user_name as Admin_name, R.resource_name, R.resource_link, R.resource_type , R.resource_status, R.resource_rank, R.remark, R.add_time from ". $ecs->table (' Suppliers_resource '). "As R left JOIN". $ecs->table (' Admin_user '). "As u on u.user_id = r.admin_id". $where; $sort _by = $filter [' sort_by ']; $sort _order = $filter [' Sort_order ']; $sql. = "GROUP by r.resource_id ORDER by". $sort _by. " ". $sort _order; if ($is _pagtion) {$sql. = "LIMIT". $filter [' page ']-1) * $filter [' page_size ']. ",". $filter [' page_size ']; } set_filter ($filter, $sql); } else {$sql = $result [' sql ']; $filter = $result [' Filter ']; } $query = $sql; $row = $db->getall ($sql); /* Format session Data */foreach ($row as $key + = $value) {if ($row [$key] [' resource_type '] = = 1) {$row [ $key [' resource_type '] = ' middle model '; }elseif ($row [$key] [' resource_type '] = = 2) {$row [$key] [' resource_type '] = ' swimwear '; }elseif ($row [$key] [' resource_type '] = = 3) {$row [$key] [' resource_type '] = ' Ali '; }elseif ($row [$key] [' resource_type '] = = 2) {$row [$key] [' resource_type '] = ' 17 net '; if ($row [$key] [' resource_status '] = = 1) {$row [$key] [' resource_status '] = ' audited '; }elseif ($row [$key] [' resource_status '] = = 2) {$row [$key] [' resource_status '] = ' deprecated ';if ($row [$key] [' resource_rank '] = = 1) {$row [$key] [' resource_rank '] = ' A '; }elseif ($row [$key] [' resource_rank '] = = 2) {$row [$key] [' resource_rank '] = ' B '; }elseif ($row [$key] [' resource_rank '] = = 3) {$row [$key] [' resource_rank '] = ' C '; if (Strpos ($row [$key] [' Resource_link '], '/http ') = = = = False) {if (Strpos ($row [$key] [' Resource_ Link '], ' https://') = = = False) {$row [$key] [' resource_link '] = Substr_replace ($row [$key] [' Resou Rce_link '], ' http://', 0, 0); }}} $arr = array (' result ' = = $row, ' filter ' + $filter, ' page_count ' = = $filter [' Page_count '], ' re Cord_count ' + $filter [' Record_count '], ' query ' and ' = $query '); return $arr;}