一个分页导航类_PHP
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Richard Heyes
// +----------------------------------------------------------------------+
/**
* Pager class
*
* Handles paging a set of data. For usage see the example.php provided.
*
*/
class Pager {
/**
* Current page
* @var integer
*/
var $_currentPage;
/**
* Items per page
* @var integer
*/
var $_perPage;
/**
* Total number of pages
* @var integer
*/
var $_totalPages;
/**
* Item data. Numerically indexed array...
* @var array
*/
var $_itemData;
/**
* Total number of items in the data
* @var integer
*/
var $_totalItems;
/**
* Page data generated by this class
* @var array
*/
var $_pageData;
/**
* Constructor
*
* Sets up the object and calculates the total number of items.
*
* @param $params An associative array of parameters This can contain:
* currentPage Current Page number (optional)
* perPage Items per page (optional)
* itemData Data to page
*/
function pager($params = array())
{
global $HTTP_GET_VARS;
$this->_currentPage = max((int)@$HTTP_GET_VARS['pageID'], 1);
$this->_perPage = 8;
$this->_itemData = array();
foreach ($params as $name => $value) {
$this->{'_' . $name} = $value;
}
$this->_totalItems = count($this->_itemData);
}
/**
* Returns an array of current pages data
*
* @param $pageID Desired page ID (optional)
* @return array Page data
*/
function getPageData($pageID = null)
{
if (isset($pageID)) {
if (!empty($this->_pageData[$pageID])) {
return $this->_pageData[$pageID];
} else {
return FALSE;
}
}
if (!isset($this->_pageData)) {
$this->_generatePageData();
}
return $this->getPageData($this->_currentPage);
}
/**
* Returns pageID for given offset
*
* @param $index Offset to get pageID for
* @return int PageID for given offset
*/
function getPageIdByOffset($index)
{
if (!isset($this->_pageData)) {
$this->_generatePageData();
}
if (($index % $this->_perPage) > 0) {
$pageID = ceil((float)$index / (float)$this->_perPage);
} else {
$pageID = $index / $this->_perPage;
}
return $pageID;
}
/**
* Returns offsets for given pageID. Eg, if you
* pass it pageID one and your perPage limit is 10
* it will return you 1 and 10. PageID of 2 would
* give you 11 and 20.
*
* @params pageID PageID to get offsets for
* @return array First and last offsets
*/
function getOffsetByPageId($pageid = null)
{
$pageid = isset($pageid) ? $pageid : $this->_currentPage;
if (!isset($this->_pageData)) {
$this->_generatePageData();
}
if (isset($this->_pageData[$pageid])) {
return array(($this->_perPage * ($pageid - 1)) + 1, min($this->_totalItems, $this->_perPage * $pageid));
} else {
return array(0,0);
}
}
/**
* Returns back/next and page links
*
* @param $back_html HTML to put inside the back link
* @param $next_html HTML to put inside the next link
* @return array Back/pages/next links
*/
function getLinks($back_html = '>')
{
$url = $this->_getLinksUrl();
$back = $this->_getBackLink($url, $back_html);
$pages = $this->_getPageLinks($url);
$next = $this->_getNextLink($url, $next_html);
return array($back, $pages, $next, 'back' => $back, 'pages' => $pages, 'next' => $next);
}
/**
* Returns number of pages
*
* @return int Number of pages
*/
function numPages()
{
return $this->_totalPages;
}
/**
* Returns whether current page is first page
*
* @return bool First page or not
*/
function isFirstPage()
{
return ($this->_currentPage == 1);
}
/**
* Returns whether current page is last page
*
* @return bool Last page or not
*/
function isLastPage()
{
return ($this->_currentPage == $this->_totalPages);
}
/**
* Returns whether last page is complete
*
* @return bool Last age complete or not
*/
function isLastPageComplete()
{
return !($this->_totalItems % $this->_perPage);
}
/**
* Calculates all page data
*/
function _generatePageData()
{
$this->_totalItems = count($this->_itemData);
$this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
$i = 1;
if (!empty($this->_itemData)) {
foreach ($this->_itemData as $value) {
$this->_pageData[$i][] = $value;
if (count($this->_pageData[$i]) >= $this->_perPage) {
$i++;
}
}
} else {
$this->_pageData = array();
}
}
/**
* Returns the correct link for the back/pages/next links
*
* @return string Url
*/
function _getLinksUrl()
{
global $HTTP_SERVER_VARS;
// Sort out query string to prevent messy urls
$querystring = array();
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
for ($i = 0, $cnt = count($qs); $i
list($name, $value) = explode('=', $qs[$i]);
if ($name != 'pageID') {
$qs[$name] = $value;
}
unset($qs[$i]);
}
}
if(is_array($qs)){
foreach ($qs as $name => $value) {
$querystring[] = $name . '=' . $value;
}
}
return $HTTP_SERVER_VARS['SCRIPT_NAME'] . '?' . implode('&', $querystring) . (!empty($querystring) ? '&' : ') . 'pageID=';
}
/**
* Returns back link
*
* @param $url URL to use in the link
* @param $link HTML to use as the link
* @return string The link
*/
function _getBackLink($url, $link = '
{
// Back link
if ($this->_currentPage > 1) {
$back = '' . $link . '';
} else {
$back = ';
}
return $back;
}
/**
* Returns pages link
*
* @param $url URL to use in the link
* @return string Links
*/
function _getPageLinks($url)
{
// Create the range
$params['itemData'] = range(1, max(1, $this->_totalPages));
$pager =& new Pager($params);
$links = $pager->getPageData($pager->getPageIdByOffset($this->_currentPage));
for ($i=0; $i
$links[$i] = '' . $links[$i] . '';
}
}
return implode(' ', $links);
}
/**
* Returns next link
*
* @param $url URL to use in the link
* @param $link HTML to use as the link
* @return string The link
*/
function _getNextLink($url, $link = 'Next >>')
{
if ($this->_currentPage _totalPages) {
$next = '' . $link . '';
} else {
$next = ';
}
return $next;
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

The horizontal figure 8 on the navigation map means haze, moderate is a yellow 8 warning signal, and severe is an orange 8 warning signal.

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

Both Android and iOS versions of Baidu Map App have released version 18.8.0, which introduces the traffic light radar function for the first time, leading the industry. According to the official introduction, after turning on the traffic light radar, it supports automatic detection of traffic lights while driving without having to enter a destination. Beidou High-Precision can position in real time. , 1 million+ traffic lights across the country automatically trigger green wave reminders. In addition, the new function also provides full silent navigation, making the map area more concise, key information clear at a glance, and no voice broadcast, allowing the driver to focus more on driving. Baidu Maps will launch a traffic light countdown function in October 2020, supporting real-time countdown prediction. Judgment, the navigation will automatically display the remaining seconds of the countdown when approaching a traffic light intersection, allowing users to always grasp the road conditions ahead. Traffic light countdown to December 31, 2022

The football navigation voice package in the "Amap Navigation" software is one of the navigation voice packages for the car version of the Amap map. The content is the navigation voice of Huang Jianxiang's football commentary version. Setting method: 1. Open the Amap software; 2. Click to enter the "More Tools" - "Navigation Voice" option; 3. Find "Huang Jianxiang Passionate Voice" and click "Download"; 4. On the pop-up page, click " Just use voice".

According to news from this site on April 29, Amap officially announced the launch of an upgraded version of driving ETA (Note from this site: ETA is the estimated time of arrival, which refers to the estimated time it will take for the user to depart from the current moment and follow a given route to the destination. ) service, which aims to help users make more accurate route planning duration and traffic condition estimates, and assist users in making travel decisions. This map application is the latest upgraded Amap App. It introduces the "ultra-large-scale graph convolutional neural network model", which can better capture and learn traffic flow patterns, support urban road networks and highway systems, and can Accurately depict the spatiotemporal dynamic changes of traffic conditions. In addition, the new version of the map further integrates the iTransformer time series prediction model to support real-time analysis.
