Thinkphp array query problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.