Home Backend Development PHP Tutorial 编撰php分页代码 mysql_fetch_arry()就是无法执行

编撰php分页代码 mysql_fetch_arry()就是无法执行

Jun 13, 2016 pm 12:40 PM
nbsp page url

编写php分页代码 mysql_fetch_arry()就是无法执行
/*
 * Created on 2013-7-30
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

  $page = $_get[page];
if(!function_exists(pageft)){
function pageft($totle,$displaypg=20,$url=''){
//定义几个全局变量:
//$page:当前页码;
//$firstcount:(数据库教程)查询的起始项;
//$pagenav:页面导航条代码,函数内部并没有将它输出;
//$_server:读取本页url"$_server["request_uri"]"所必须。
global $page,$firstcount,$pagenav,$_server;
$globals["displaypg"]=$displaypg;
if(!$page) $page=1;
//如果$url使用默认,即空值,则赋值为本页url:
if(!$url){ $url=$_server["request_uri"];}

//url分析:

$parse_url=parse_url($url);
$url_query=$parse_url["query"]; //单独取出url的查询字串
if($url_query){
$url_query=preg_replace("/(^|&)page=$page/","",$url_query);
//将处理后的url的查询字串替换原来的url的查询字串:
$url=str_replace($parse_url["query"],$url_query,$url);
//在url后加page查询信息,但待赋值:
if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}

//页码计算:

$lastpg=ceil($totle/$displaypg); //最后页,也是总页数
$page=min($lastpg,$page);
$prepg=$page-1; //上一页
$nextpg=($page==$lastpg ? 0 : $page+1); //下一页
$firstcount=($page-1)*$displaypg;

//开始分页导航条代码:

$pagenav="显示第 ".($totle?($firstcount+1):0)."-".min($firstcount+$displaypg,$totle)." 条记录,共 $totle 条记录";
//如果只有一页则跳出函数:
if($lastpg $pagenav.=" 首页 ";
if($prepg)
$pagenav.=" 前页 ";
else $pagenav.=" 前页 ";
if($nextpg)
$pagenav.=" 后页 ";
else $pagenav.=" 后页 ";
$pagenav.=" 尾页 ";

//下拉跳转列表,循环列出所有页码:
$pagenav.=" 到第  页,共 $lastpg 页";
}
}


include("conn.php");

$result=mysql_query("SELECT * FROM `test`");
$total=mysql_num_rows($result);
//调用pageft(),每页显示10条信息(使用默认的20时,可以省略此参数),使用本页URL(默认,所以省略掉)。
pageft($total,3);
echo $pagenav;

$result="SELECT * FROM `test` limit $firstcount,$displaypg";

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 Article Tags

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)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE Error Problems in Windows 11/10 Repair

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

Display scaling guide on Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

How to turn off private browsing authentication for iPhone in Safari?

See all articles