Thinkphp array query
$ Map ['id'] = I ('Get. ID'); $ map ['CID'] = I ('Get. cid '); $ m-> where ($ map)-> find ();
The generated SQL statement is
SELECT 'id', 'title', 'Pic 'FROM 'new' WHERE 'id' = null AND 'CID' = null LIMIT
That is to say, when the obtained ID and CID are empty, this query condition still exists, but the value is changed to null, so that no data can be found,
The correct one is that when the obtained value is null, the where condition should not exist, that is, to search for all information,
What is the reason?
Reply to discussion (solution)
Thinkphp is never used, but more than once has seen similar problems. it is probably a bug of thinkphp.
If you cannot modify the code, you can pre-process it first.
$ Map ['id'] = I ('Get. ID'); $ map ['CID'] = I ('Get. cid '); $ map = array_diff ($ map, array (''); // filter out empty elements $ m-> where ($ map)-> find ();
Well, it is indeed a BUG. I used a loop to remove this, but there were too many codes. it was much easier to use this function.