thinkphp中分页保持查询条件不变的问题
手册中:
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这些条件的。
请问楼主你是怎么解决的呢

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

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



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

MySQL and PL/SQL are two different database management systems, representing the characteristics of relational databases and procedural languages respectively. This article will compare the similarities and differences between MySQL and PL/SQL, with specific code examples to illustrate. MySQL is a popular relational database management system that uses Structured Query Language (SQL) to manage and operate databases. PL/SQL is a procedural language unique to Oracle database and is used to write database objects such as stored procedures, triggers and functions. same
