Table of Contents
PHP基于数组实现的分页函数实例,php数组分页实例
怎用PHP数组实现文件分页
php怎实现查询oracle然后分页显示,最好是一个类加实例,了
Home php教程 php手册 PHP基于数组实现的分页函数实例,php数组分页实例

PHP基于数组实现的分页函数实例,php数组分页实例

Jun 13, 2016 am 09:26 AM
php function Pagination array

PHP基于数组实现的分页函数实例,php数组分页实例

分页功能是PHP程序设计中非常常见的功能,不同于以往的,今天本文介绍的是PHP基于数组实现的分页函数。

关于数组的分页函数,用数组进行分页的好处是可以方便的进行联合多表查询,只需要将查询的结果放在数组中就可以了以下是数组分页的函数,函数page_array用于数组的分页,函数show_array用于分页函数的操作及显示,需要配合使用。两个函数通过全局变量$countpage发生联系,此变量用于跟踪总页码数。

具体实例代码如下:

<&#63;php
/**
 * 数组分页函数 核心函数 array_slice
 * 用此函数之前要先将数据库里面的所有数据按一定的顺序查询出来存入数组中
 * $count  每页多少条数据
 * $page  当前第几页
 * $array  查询出来的所有数组
 * order 0 - 不变   1- 反序
 */ 
function page_array($count,$page,$array,$order){
  global $countpage; #定全局变量
  $page=(empty($page))&#63;'1':$page; #判断当前页面是否为空 如果为空就表示为第一页面 
    $start=($page-1)*$count; #计算每次分页的开始位置
  if($order==1){
   $array=array_reverse($array);
  }  
  $totals=count($array); 
  $countpage=ceil($totals/$count); #计算总页面数
  $pagedata=array();
 $pagedata=array_slice($array,$start,$count);
  return $pagedata; #返回查询数据
}
/**
 * 分页及显示函数
 * $countpage 全局变量,照写
 * $url 当前url
 */
function show_array($countpage,$url){
   $page=empty($_GET['page'])&#63;1:$_GET['page'];
 if($page > 1){
   $uppage=$page-1;
 }else{
  $uppage=1;
 }
 if($page < $countpage){
   $nextpage=$page+1;

 }else{
   $nextpage=$countpage;
 }
    $str='<div style="border:1px; width:300px; height:30px; color:#9999CC">';
 $str.="<span>共 {$countpage} 页 / 第 {$page} 页</span>";
 $str.="<span><a href='$url&#63;page=1'>  首页 </a></span>";
 $str.="<span><a href='$url&#63;page={$uppage}'> 上一页 </a></span>";
 $str.="<span><a href='$url&#63;page={$nextpage}'>下一页 </a></span>";
 $str.="<span><a href='$url&#63;page={$countpage}'>尾页 </a></span>";
 $str.='</div>';
 return $str;
}
&#63;>

Copy after login

希望本文所述实例对大家的PHP程序设计能起到一定的借鉴作用。

怎用PHP数组实现文件分页


你没有>,里面的39章,专门一章来讲文件上传,非常详细,最简单的部分如下:

POST 方法上传

本特性可以使用户上传文本和二进制文件。用 PHP 的认证和文件操作函数,可以完全控制允许哪些人上传以及文件上传后怎样处理。 

PHP 能够接受任何来自符合 RFC-1867 标准的浏览器(包括 Netscape Navigator 3 及更高版本,打了补丁的 Microsoft Internet Explorer 3 或者更高版本)上传的文件。 

相关的设置: 请参阅 php.ini 的 file_uploads,upload_max_filesize,upload_tmp_dirpost_max_size 以及 max_input_time 设置选项。 

请注意 PHP 也支持 PUT 方法的文件上传,Netscape Composer 和 W3C 的 Amaya 客户端使用这种方法。请参阅对 PUT 方法的支持以获取更多信息。 

例 39.1. 文件上传表单

可以如下建立一个特殊的表单来支持文件上传: 

    



    
    
    
    Send this file: >
 

php怎实现查询oracle然后分页显示,最好是一个类加实例,了

oracle 实现分页要用到rownum 代码如下
select * from (select t.* rownum row_id form (select * from 表名) t ) where row_id>=1 and row_id这条SQL语句就可以实现分页查询,当然光有SQL还是不行,用以下的PHP 函数就可实现分页了。
/*分页函数*/
function page($page,$total,$phpfile,$pagesize=10,$pagelen=10,$str='')
{
$pagecode = '';//定义变量,存放分页生成的HTML
$page = intval($page);//避免非数字页码
$total = intval($total);//保证总记录数值类型正确
if(!$total) return array();//总记录数为零返回空数组
$pages = ceil($total/$pagesize);//计算总分页
//处理页码合法性
if($pageif($page>$pages) $page = $pages;
//计算查询偏移量
$offset = $pagesize*($page-1)+1;
//页码范围计算
$init = 1;//起始页码数
$max = $pages;//结束页码数
$pagelen = ($pagelen%2)?$pagelen:$pagelen+1;//页码个数
$pageoffset = ($pagelen-1)/2;//页码个数左右偏移量
//生成html
$pagecode='

';
$pagecode.="共".$total."条信息 第".$page."页/共".$pages."页\n";//第几页,共几页
//如果是第一页,则不显示第一页和上一页的连接
if($page!=1){
$pagecode.=" 首页 ";//第一页
$pagecode.="
上页 ";//上一页
}
//分页数大于页码个数时可以偏移
if($pages>$pagelen)
{
//如果当前页小于等于左偏移
if($page{
$init=1;
$max = $pagelen;
}else
{
//如......余下全文>>
来自UC浏览器  
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles