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发生联系,此变量用于跟踪总页码数。

具体实例代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

<&#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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

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,

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

See all articles