Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php 换页后,序号又重新开始的问题 + 急急急 ?

php 换页后,序号又重新开始的问题 + 急急急 ?

Jun 23, 2016 pm 02:22 PM

php php 换页后,序号的问题 

$MYSQL->query("select cu.*,cy.name from customer cu,custtype cy where 1=1 and cu.code=cy.code limit 0,18");
for($i=1;$i $MYSQL->fetch($i);
$customerid=$MYSQL->data[customerid];  // 客户编号
$KSName=$MYSQL->data[KSName];  //  用户名称 - 简称
echo "$i"; //序号
echo "$customerid";  // 客户编号
echo "$KSName"; //用户名称 - 简称
?>

我是每18 条记录换一页,在第一页序号是从 1 - 18 ,但是我切换到第2页时,序号又是从1 开始一直到第18,第3页同样如此,可能是因为我分页的缘故,我试 了,如果不分页时没有问题的,但是这里我不可能不分页的,求各位没有没好的方法解决这个问题。。




回复讨论(解决方案)

 limit  0,18  
你这里limit第一个一直是0,当然是那个结果啦

limit 0,18 这里应该是分页参数传过去。

for($i=1;$i echo "

$i"; //序号

你的序号是程序产生的,当然都是从 1 开始

楼上的回复这是解决换页后内容不变的问题
不能解决序号重新开始的问题

我的意思是,如何解决我换页后,序号从第一页的最后一个序号开始 累加,如1-18,第二页序号就是从 19开始。而不是又从 1开始。。

各位说的都是产生的原因,产生的原因我知道,楼上的兄弟,都没说解决的方法。

设期望的页号由 $_GET['page'] 传入,则有

$offs = 18 * isset($_GET['page']) ? $_GET['page'] - 1 : 0;$MYSQL->query("select cu.*,cy.name from customer cu,custtype cy where 1=1 and cu.code=cy.code limit $offs,18");for($i=$offs+1;$i<$offs+$count;$i++){ $MYSQL->fetch($i);	$customerid=$MYSQL->data[customerid];  // 客户编号$KSName=$MYSQL->data[KSName];  //  用户名称 - 简称echo "<td align='center'>$i</td>"; //序号echo "<td align='center'>$customerid</td>";  // 客户编号echo "<td align='center'>$KSName</td>"; //用户名称 - 简称
Copy after login

回复 6 楼的兄弟,好像还是不行,

我觉得版主的方法是可以的,先想办法把你页码传入$offs,后面就按照6#的写就可以了。

单独设置变量,计算序号

function toolkit_pages($page, $total, $phpfile, $pagesize = 3, $pagelen = 3, $link = "&") {		$num_t_count = $total;		$phpfile = "index.php?" . $phpfile;		$pagecode = ''; //定义变量,存放分页生成的HTML		$page = intval ( $page ); //避免非数字页码		$total = intval ( $total ); //保证总记录数值类型正确		if (! $total)			return array (); //总记录数为零返回空数组		$pages = ceil ( $total / $pagesize ); //计算总分页		//处理页码合法性		if ($page < 1)			$page = 1;		if ($page > $pages)			$page = $pages;			//计算查询偏移量		$offset = $pagesize * ($page - 1);		//页码范围计算		$init = 1; //起始页码数		$max = $pages; //结束页码数		$pagelen = ($pagelen % 2) ? $pagelen : $pagelen + 1; //页码个数		$pageoffset = ($pagelen - 1) / 2; //页码个数左右偏移量				//生成html		$pagecode = '<div class="page"><span>' . $total . "</span> ";		$pagecode .= "<span>$page/$pages</span> "; //第几页,共几页		//如果是第一页,则不显示第一页和上一页的连接		if ($page != 1) {			$pagecode .= "<a href=\"{$phpfile}" . $link . "page=1\"><<</a> "; //第一页			$pagecode .= "<a href=\"{$phpfile}" . $link . "page=" . ($page - 1) . "\">Prev</a> "; //上一页		}		//分页数大于页码个数时可以偏移		if ($pages > $pagelen) {			//如果当前页小于等于左偏移			if ($page <= $pageoffset) {				$init = 1;				$max = $pagelen;			} else { //如果当前页大于左偏移				//如果当前页码右偏移超出最大分页数				if ($page + $pageoffset >= $pages + 1) {					$init = $pages - $pagelen + 1;				} else {					//左右偏移都存在时的计算					$init = $page - $pageoffset;					$max = $page + $pageoffset;				}			}		}		//生成html		for($i = $init; $i <= $max; $i ++) {			if ($i == $page) {				$pagecode .= '<span>' . $i . '</span> ';			} else {				$pagecode .= "<a href=\"{$phpfile}" . $link . "page={$i}\">$i</a> ";			}		}		if ($page != $pages) {			$pagecode .= "<a href=\"{$phpfile}" . $link . "page=" . ($page + 1) . "\">Next</a> "; //下一页			$pagecode .= "<a href=\"{$phpfile}" . $link . "page={$pages}\">>></a> "; //最后一页		}		$pagecode .= '</div>';				return array ('pagecode' => $pagecode, 'sqllimit' => ' limit ' . $offset . ',' . $pagesize );		}//引用说明/*分页列表*/		if (url_get ( 'count_page' ) != '') {			$count_page = url_get ( 'count_page' );		} else {			$count_page = 15;		}		if (url_get ( 'page' ) <= 0 || url_get ( 'page' ) == '') {			$page = 1;		} else {			$page = url_get ( 'page' );		}		$t_count = $this->Cmspage_model->row_array ();//统计记录个数自己写个sql语句		$t_first = ($page - 1) * $count_page;		$list = $this->Cmspage_model->result_array ( $t_first, $count_page );//返回数组自己写个sql语句		//引用分页函数		$getpageinfo = toolkit_pages ( $page, $t_count, "?c=page&m=index", $count_page, 8 );
Copy after login

#10 楼兄弟写的好像是分页的代码,跟我的问题,好像关系不大吧。

求大神,解决 。。。。。。。。。。。。。。。。。。。。

求大神,解决 。。。。。。。。。。。。。。。。。。。。

6楼已经帮你解决了,你还在求,总不能要求别人帮你写出完整代码吧。重点去看一下sql语句的limit的用法。你技术分800多是如何得来的?你是来逗我们玩的吧。。。。。

#14 ,兄弟,你没搞清楚,问题,就不要瞎说。。ok !!!!!!!!!!

#14 ,兄弟,你没搞清楚,问题,就不要瞎说。。ok !!!!!!!!!!
你换页码的时候,应该是是要拿到url传入的$page值的,比如是$_GET['page'];
然后,你每分一页的时候,都是有一个$page_size的,你的$page_size=18;
所以,你在页面上显示的时候,那个列表的id号应该是:($page-1)*$page_size+$i;$i的值就是数组的下标。

$page=$_GET['page'];$page_size=18;$count=$MYSQL->query("select count(*) from customer cu,custtype cy where 1=1 and cu.code=cy.code");$pages = ceil($count/$page_size);if($page<1) $page = 1;if($page>$pages)$page = $pages;$offset = ($page-1) * $page_size;if($offset<0) $offset = 0;$MYSQL->query("select cu.*,cy.name from customer cu,custtype cy where 1=1 and cu.code=cy.code  limit ".$offset.",".$page_size);for($i=1;$i<$count;$i++){	$MYSQL->fetch($i);		$customerid=$MYSQL->data['customerid'];  // 客户编号	$KSName=$MYSQL->data['KSName'];  //  用户名称 - 简称	$thisPage=($page-1).$page_size+$i;	echo "<td align='center'>".$thisPage."</td>"; //序号	echo "<td align='center'>$customerid</td>";  // 客户编号	echo "<td align='center'>$KSName</td>"; //用户名称 - 简称}
Copy after login


我不知道$MYSQL这个对象的具体情况,所以,其他地方是一个思路,重点看

$thisPage=($page-1).$page_size+$i;

这句。

更正一下,竟然不能编辑,应该是:$thisPage=($page-1)*$page_size+$i;

恩, #16 楼兄弟说的是对的。。 太感谢了

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)

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,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

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.

See all articles