一个分页导航类_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;
}
}
?>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

在C語言中,if語句通常用於基於單一條件執行特定程式碼區塊。但是,透過使用邏輯運算子(如 &&、|| 和 !),可以組合多個條件來進行判斷。包括使用邏輯與(&&)判斷多個條件、使用邏輯或(||)判斷至少一個條件、使用邏輯非(!)判斷單一條件的否定,以及嵌套if語句和使用括號明確優先權。

機器之能報道編輯:吳昕國內版的人形機器人+大模型組隊,首次完成疊衣服這類複雜柔性材料的操作任務。隨著融合了OpenAI多模態大模型的Figure01揭開神秘面紗,國內同行的相關進展一直備受關注。就在昨天,國內"人形機器人第一股"優必選發布了人形機器人WalkerS深入融合百度文心大模型後的首個Demo,展示了一些有趣的新功能。現在,得到百度文心大模型能力加持的WalkerS是這個樣子的。和Figure01一樣,WalkerS沒有走動,而是站在桌子後面完成一系列任務。它可以聽從人類的命令,折疊衣物

C語言return的用法有:1、對於傳回值類型為void的函數,可以使用return語句來提前結束函數的執行;2、對於傳回值型別不為void的函數,return語句的作用是將函數的執行結果傳回給呼叫者;3、提前結束函數的執行,在函數內部,我們可以使用return語句來提前結束函數的執行,即使函數並沒有回傳值。

原始碼:publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}#輸出上述程式碼的輸出可以簡單地得出結論:return在finally之前執行,我們來看下字節碼層面上發生了什麼事情。下面截取case1方法的部分字節碼,並且對照源碼,將每個指令的含義註釋在

百度地圖App安卓版/iOS版都已發布18.8.0版本,首次引入紅綠燈雷達功能,業界領先據官方介紹,開啟紅綠燈雷達後,支援開車自動探測紅綠燈,不用輸入目的地,北斗高精可以即時定位,全國100萬+紅綠燈自動觸發綠波提醒。除此之外,新功能還提供全程靜音導航,使圖區更簡潔,關鍵訊息一目了然,且無語音播報,使駕駛員更加專注駕駛百度地圖於2020年10月上線紅綠燈倒數功能,支援即時讀秒預判,導航會在接近紅綠燈路口時,自動展示倒數剩餘秒數,讓使用者隨時掌握前方路況。截至2022年12月31日,紅綠燈倒數

足球導航語音包在「高德導航」軟體中,是高德地圖車機版導航語音包的其中一種,內容為黃健翔足球解說版本的導航語音。設定方式:1、開啟高德地圖軟體;2、點擊進入“更多工具”-“導航語音”選項;3、找到“黃健翔熱血語音”,點擊“下載”;4、在彈出的頁面,點擊“使用語音」即可。

本站4月29日消息,高德地圖官宣推出升級版的駕車ETA(本站註:ETA即預估到達時間,指的是用戶在當前時刻出發按照給定路線前往目的地預計需要的時長)服務,該服務旨在幫助用戶的路線規劃時長和路況預估更為精準,輔助用戶進行出行決策。該地圖應用程式是最新升級的高德地圖App,引入了“超大規模圖卷積神經網路模型”,該模型可以更好地捕捉和學習交通流動規律,支持城市道路網絡、高速公路系統,能以高精準度刻畫交通狀況的時空動態變化。在此外,全新版本的地圖也進一步融合了iTransformer時序預測模型,支援即時解析
