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 楼兄弟说的是对的。。 太感谢了

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 makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

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 is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

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


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 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment