php+mysql 分页问题
求教:php+mysql分页 ,先贴代码,再描述问题
代码:
<br /><br /><br />$page=isset($_GET['page'])?intval($_GET['page']):1; //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。<br />$searchinfo=isset($_GET['search'])?($_GET['search']):"-1"; <br />$search=($searchinfo=='请输入关键字')?-1:$searchinfo;<br /><br />$num=1; //每页显示3条数据<br /><br />/*<br />首先咱们要获取数据库中到底有多少数据,才能判断具体要分多少页,具体的公式就是<br />总数据库除以每页显示的条数,有余进一。<br />也就是说10/3=3.3333=4 有余数就要进一。<br />*/<br /> if ($config[NEEDDB]) { //if need db<br /> $dbLink = DBPool::getLink($config[DBDRIVER]);<br /> $daoImpl = DAOImpl::getImpl($dbLink, $config[TABLEPRE][BACKEND]); <br /> $config[DBLINK] = $dbLink;<br /> $config[DAOIMPL] = $daoImpl;<br />}<br />$adRs = $config[DAOIMPL]->adSearchCount($search);<br />//$adList = rs2Array($adRs);<br />$adList=mysql_fetch_array($adRs);<br />mysql_free_result($adRs);<br />//DBPool::closeLink($config[DBLINK]);<br />if(count($adList)>0){<br />$total=$adList[0]['cn']; //查询所有的数据<br />}<br />else{<br /> $total=0;<br />}<br /><br />$url='views/adSearchResult.php';//获取本页URL<br />//页码计算<br />$pagenum=ceil($total/$num); //获得总页数,也是最后一页<br />$page=min($pagenum,$page);//获得首页<br />$prepg=$page-1;//上一页<br />$nextpg=($page==$pagenum ? 0 : $page+1);//下一页<br />$offset=($page-1)*$num; //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。<br />//开始分页导航条代码:<br />$pagenav="显示第 <B>".($total?($offset+1):0)."</B>-<B>".min($offset+10,$total)."</B> 条记录,共 $total 条记录 ";<br />//如果只有一页则跳出函数:<br />//if($pagenum<=1) return false;<br />$pagenav.=" <a href=javascript:dopage('result','$url?page=1');>首页</a> ";<br />if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$prepg');>前页</a> "; else $pagenav.=" 前页 ";<br />if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$nextpg');>后页</a> "; else $pagenav.=" 后页 ";<br />$pagenav.=" <a href=javascript:dopage('result','$url?page=$pagenum');>尾页</a> ";<br />$pagenav.="</select> 页,共 $pagenum 页";<br />//假如传入的页数参数大于总页数,则显示错误信息<br />If($page>$pagenum){<br /> Echo "Error : Can Not Found The page ".$page;<br /> Exit;<br />}<br />$adSearchRs = $config[DAOIMPL]->getADSearchInfo($search,$offset,$page);<br />$adSearchList = rs2Array($adSearchRs);<br />//mysql_free_result($adSearchRs);<br />foreach ( $adSearchList as $it){<br />//While($it=mysql_fetch_array($adSearchRs)){<br /> Echo '<div class="sylist1"><br /> <input type="checkbox" class="check" name="checkbox" id="checkbox'.$it['id'].'" value="'.$it['id'].'"/><br /> </div><br /> <div class="sylist2">'.$it['title'].'</div><br /> <div class="sylist3">'.$it['subject'].'</div><br /> <div class="sylist4">'.$it['pic_url'].'</div><br /> <div class="sylist5">'.$it['advert_url'].'</div><br /> <div class="sylist6">'.$it['if_valid'].'</div><br /> </div>';<br />}//显示数据<br /><br />echo $pagenav;//输出分页导航<br /><br /><br />
问题描述:分页思路:先计算出查询条件的记录条数,然后根据页码和每页条数计算出分页数据(存在两次分页)。
第一次查询,是ok的,能够返回满足条件的数据条数,($adRs = $config[DAOIMPL]->adSearchCount($search););但是第二次查询执行后就报错了,报错信息是:

------解决方案--------------------
那就是 $adSearchRs = $config[DAOIMPL]->getADSearchInfo($search,$offset,$page); 已经出错了!
你的 sql 指令是 call audioconver.p_advert_qry('-1',0,1) 吗?
正确吗?结果返回给谁了?
------解决方案--------------------
commands out sync: you can't run this command new
这是“命令不同步”的原因,如果遇到该错误,说明正在以错误顺序调用客户端函数
你执行的是 call 命令,没有 select
所以会产生两个结果集
第一个是 select 的结果集,由于没有 select 命令,所以是无效的不能 php 处理成资源
第二个才是 call 的结果集
虽然 mysql 提供了 C 函数 mysql_next_result 用于移动结果集
但 php 的 mysql 扩展并没有提供该函数,所以可认为php 的 mysql 不能很好的支持存储过程(因为 mysql4 并不支持存储过程)
mysqli 扩展提供了 mysqli_next_result 函数,所以如果使用了存储过程,最好是用 mysqli 驱动
附上解决该问题的 C 代码
do<br> {<br> result=mysql_store_result(&conn);<div class="clear"> </div>

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

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