手册中:
import('ORG.Util.Page');// 导入分页类$mapcount = $User->where($map)->count();// 查询满足要求的总记录数$Page = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数//分页跳转的时候保证查询条件foreach($map as $key=>$val) { $Page->parameter .= "$key=".urlencode($val).'&';}$show = $Page->show();// 分页显示输出
这里我的查询条件使用了in
$map['code'] = array('in',$array);
当点第二页时查询条件就不成功。是不是这里不能用in?
回复讨论(解决方案)
仅仅urlencode还不够,还要先json或者serialize
foreach($map as $key=>$val) { $Page->parameter .= "$key=".urlencode(json_encode($val)).'&';}
改成这样还是不行啊!
你的$array 哪里来的 $_GET $_POST 还是 $_REQUEST
我这里的$array 是用$_POST里的一个参数为条件到数据库中的一个表里查询出一个字段值的数组。
这个问题我也遇到了,并且找到了解决的方法了
import('ORG.Util.Page');// 导入分页类
$count=$res->where($sear)->count();//查询数据条数
$Page=new Page($count,2);//实例化分页函数
//分页跳转的时候保证查询条件
foreach($sear as $key=>$val) {
if(!is_array($val)) {
$Page->parameter .= "$key=".urlencode($val)."&";//赋值给Page
}
}
$show=$Page->show();//分页显示输出
这里添加了一个判断就实现了
你的数组内容是:
$map['code'] = array('in',$array);
但是查询条件却是:
"$key=".urlencode($val).'&'
这样当然不行
上面这个还是不行
foreach($map as $key=>$val) {
$Page->parameter .= "$key=".urlencode($val).'&';
echo "$key=".urlencode($val)."&"; //输出来看看不就行了吗
}
我找解决的方法了
//分页跳转的时候保证查询条件
foreach($map as $key=>$val) {
$Page->parameter .= "$key=".urlencode($val).'&';
}
"$key=".urlencode($val).'&';这里面的$val是指的你的条件
你的是$map['code'] = array('in',$array);
那就改成
foreach($map as $key=>$val) {
$Page->parameter .= "$key=".urlencode($code).'&';
}
你就不能在 foreach($map as $key=>$val) {
之前看一下 $map 吗(print_r($map))
知道数据时如何保存的,不也就知道该怎么做了吗?
//查询
public function search() {
$res=D('Info');
$name=$_REQUEST['name'];
$sear['name'] = array('like','%'.$name.'%');
import('ORG.Util.Page');// 导入分页类
$count=$res->where($sear)->count();//查询数据条数
$Page=new Page($count,2);//实例化分页函数
//分页跳转的时候保证查询条件
foreach($name as $key=>$val) {
$Page->parameter .= "$key=".urlencode($val)."&";//赋值给Page
}
$show=$Page->show();//分页显示输出
这是我用的查询分页的代码你看下吧,刚才发的那条虽然能查出来但是不符合规则
这是我总结的文档http://blog.sina.com.cn/s/blog_80742e010101acfq.html,你看下吧
多谢各位,但是还是不行的。
我又仔细的看了一下page.class.php的源码,page->show方法中会对page->parameter进行处理。parameter属性支持2种方式传值:字符串和数组。字符串采用var1=val1&var2=val2...的格式。请看源码中的处理:
$url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter; $parse = parse_url($url); if(isset($parse['query'])) { parse_str($parse['query'],$params); unset($params[$p]); $url = $parse['path'].'?'.http_build_query($params); }
这样的话的确是处理不了in、like、between这些条件的。
请问楼主你是怎么解决的呢

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

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.
