Home > Backend Development > PHP Tutorial > thinkphp数组查询有关问题

thinkphp数组查询有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:24:49
Original
890 people have browsed it

thinkphp数组查询问题
thinkphp中查询条件为

$map['id'] = I('get.id');<br />$map['cid'] = i('get.cid');<br />$m->where($map)->find();
Copy after login


生成的SQL语句为
SELECT `id`,`title`,`pic` FROM `news` WHERE `id` = null AND `cid` = null  LIMIT 0,12
Copy after login


也就是说,当获取的ID和CID为空时,这个查询条件还是存在的,但值变成了null,这样查不到数据,
正确的应该是当获取的值为空时,where条件就应该不存在了,就是搜索全部的信息了,
请问这个什么原因呢?
------解决思路----------------------
从不用 thinkphp,不过不止一次见到类似的问题,估计是他的一个 bug
如果没有能力修改他的代码,可以先预处理一下
$map['id'] = I('get.id');<br />$map['cid'] = i('get.cid');<br />$map = array_diff($map, array('')); //过滤掉空元素<br />$m->where($map)->find();
Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template