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 "
echo "
echo "
?>
我是每18 条记录换一页,在第一页序号是从 1 - 18 ,但是我切换到第2页时,序号又是从1 开始一直到第18,第3页同样如此,可能是因为我分页的缘故,我试 了,如果不分页时没有问题的,但是这里我不可能不分页的,求各位没有没好的方法解决这个问题。。
回复讨论(解决方案)
limit 0,18
你这里limit第一个一直是0,当然是那个结果啦
limit 0,18 这里应该是分页参数传过去。
for($i=1;$i echo "
你的序号是程序产生的,当然都是从 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>"; //用户名称 - 简称
回复 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 );
#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>"; //用户名称 - 简称}
我不知道$MYSQL这个对象的具体情况,所以,其他地方是一个思路,重点看
$thisPage=($page-1).$page_size+$i;
这句。
更正一下,竟然不能编辑,应该是:$thisPage=($page-1)*$page_size+$i;
恩, #16 楼兄弟说的是对的。。 太感谢了

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
