PHP分页类添加查询条件
请问分页类显示的页码怎么加入查询的条件,现在查询出来的页码链接都没有加上查询条件的
php分页类源码
<?php//为了避免重复包含文件而造成错误,加了判断函数是否存在的条件:@$page = $_GET['page'];if(!function_exists('pageft')){//定义函数pageft(),三个参数的含义为://$totle:信息总数;//$displaypg:每页显示信息数,这里设置为默认是20;//$url:分页导航中的链接,除了加入不同的查询信息“page”外的部分都与这个URL相同。// 默认值本该设为本页URL(即$_SERVER["REQUEST_URI"]),但设置默认值的右边只能为常量,所以该默认值设为空字符串,在函数内部再设置为本页URL。function pageft($totle,$displaypg=20,$shownum=0,$showtext=0,$showselect=0,$showlvtao=7,$url=''){//定义几个全局变量://$page:当前页码;//$firstcount:(数据库)查询的起始项;//$pagenav:页面导航条代码,函数内部并没有将它输出;//$_SERVER:读取本页URL“$_SERVER["REQUEST_URI"]”所必须。global $page,$firstcount,$pagenav,$_SERVER;//为使函数外部可以访问这里的“$displaypg”,将它也设为全局变量。注意一个变量重新定义为全局变量后,原值被覆盖,所以这里给它重新赋值。$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中可能包含了页码信息,我们要把它去掉,以便加入新的页码信息。//这里用到了正则表达式,请参考“PHP中的正规表达式”$url_query=ereg_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;//开始分页导航条代码:if ($showtext==1){$pagenav="<span class='disabled'>".($totle?($firstcount+1):0)."-".min($firstcount+$displaypg,$totle)."/$totle 记录</span><span class='disabled'>$page/$lastpg 页</span>";}else{$pagenav=""; }//如果只有一页则跳出函数:if($lastpg<=1) return false;if($prepg) $pagenav.="<a href='$url=1'>首页</a>"; else $pagenav.='<span class="disabled">首页</span>';if($prepg) $pagenav.="<a href='$url=$prepg'>上一页</a>"; else $pagenav.='<span class="disabled">上一页</span>';if ($shownum==1){ $o=$showlvtao;//中间页码表总长度,为奇数 $u=ceil($o/2);//根据$o计算单侧页码宽度$u $f=$page-$u;//根据当前页$currentPage和单侧宽度$u计算出第一页的起始数字 //str_replace('{p}',,$fn)//替换格式 if($f<0){$f=0;}//当第一页小于0时,赋值为0 $n=$lastpg;//总页数,20页 if($n<1){$n=1;}//当总数小于1时,赋值为1 if($page==1){ $pagenav.='<span class="current">1</span>'; }else{ $pagenav.="<a href='$url=1'>1</a>"; } /////////////////////////////////////// for($i=1;$i<=$o;$i++){ if($n<=1){break;}//当总页数为1时 $c=$f+$i;//从第$c开始累加计算 if($i==1 && $c>2){ $pagenav.='...'; } if($c==1){continue;} if($c==$n){break;} if($c==$page){ $pagenav.='<span class="current">'.$page.'</span>'; }else{ $pagenav.="<a href='$url=$c'>$c</a>"; } if($i==$o && $c<$n-1){ $pagenav.='...'; } if($i>$n){break;}//当总页数小于页码表长度时 } if($page==$n && $n!=1){ $pagenav.='<span class="current">'.$n.'</span>'; }else{ $pagenav.="<a href='$url=$n'>$n</a>"; }}if($nextpg) $pagenav.="<a href='$url=$nextpg'>下一页</a>"; else $pagenav.='<span class="disabled">下一页</span>';if($nextpg) $pagenav.="<a href='$url=$lastpg'>尾页</a>"; else $pagenav.='<span class="disabled">尾页</span>';if ($showselect==1){//下拉跳转列表,循环列出所有页码:$pagenav.="跳至<select name='topage' size='1' onchange='window.location=\"$url=\"+this.value'>\n";for($i=1;$i<=$lastpg;$i++){if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n";else $pagenav.="<option value='$i'>$i</option>\n";}$pagenav.="</select>页";}}}?>
回复讨论(解决方案)
很不错。收藏先
最近回复老是提示出错
楼主贴的代码貌似不完全呀,查询条件估计在另外的其它代码,只是想要一个分页类,我可以提供,如有需要可以私信与我。
<h2 id="销售订单列表">销售订单列表</h2><form id="add_form" action="sale_list.php?page=1" method="post"><div class="content"><?PHPinclude_once ("page.class.php");include_once ("conn.php");$pageSize=10; if(empty($_GET['page'])) { $spage=1; } else { $spage=$_GET['page']; }$start=$spage*$pageSize-$pageSize;if(!empty($_POST['findtext'])){$findtext=$_POST['findtext'];$findtype=$_POST['findtype'];$findsql="AND `".$findtype."`='".$findtext."'";$findpage=$findtype."=".$findtext;}else{$findsql='';$findpage='';}$result = mysql_query("SELECT COUNT(*) AS count FROM `sale_orders` WHERE `number`>0 ".$findsql); $row = mysql_fetch_array($result, MYSQL_ASSOC); $total= $row['count'];$SQL = "SELECT * FROM `sale_orders` WHERE `number`>0 ".$findsql." LIMIT $start , $pageSize";$result = mysql_query($SQL); pageft($total,$pageSize,1,1,1,5);?><div id="opt"> <div id="query"> <label></label> <select name="findtype"> <option value="order_id" selected="selected" >订单号</option> <option value="sku" >订单SKU</option> </select> <input type="text" class="input" id="sale_text" name="findtext" /> <input type="submit" class="btn" id="find_btn" value="查 询" /> </div> </div> <table width="195%" cellspacing="1" bgcolor="#0093C4" summary="user infomation table"> <thead> <tr> <th width="17%"><span class="STYLE3">订单号</span></th> <th width="11%" class="STYLE3">客户姓名</th> <th width="17%" class="STYLE3">订单SKU</th> <th width="42%" class="STYLE3">产品名称</th> <th width="6%" class="STYLE3">购买数量</th> <th width="7%" class="STYLE3">订单状态</th> </tr> </thead> <tbody> <?PHP while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?> <tr> <td><?PHP echo $row['order_id'] ?></td> <td><?PHP echo $row['buyer_name'] ?></td> <td><?PHP echo $row['sku'] ?></td> <td><?PHP echo $row['product_name'] ?></td> <td><?PHP echo $row['quantity_purchased'] ?></td> <td><?PHP $shipments=$row['shipments']; switch ($shipments){case "0": echo "未发货"; break;case "1": echo "已发货"; break; case "2": echo "已取消"; break;} ?></td> </tr> <?PHP } ?> </tbody> </table></div></form><div class="digg"><?php echo $pagenav;?></div>
我贴代码老是提示出错,经常贴不上来,这个分页类现在能分页,就是分页按钮链接里面没有查询条件,我想请问怎么把查询条件也加入到链接里面
怎么添加查询条件??
他不是有个 $url 参数吗?
就是做这个用的
怎么添加查询条件??

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

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 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 type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

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 is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

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.
