In thinkphp, you can use "_complex" to query multiple conditions. "_complex" is often used to implement compound queries. You can set an "AND" relationship between the first query and the second query condition. , the syntax is "condition one ['_complex'] = condition two".
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
Open the thinkphp controller file and create a function is_power for testing.
Create the first query condition and save it in the $where array. For example, query the records with id equal to 1. Create a second query condition, and use _logic to set the query condition to be an "OR" relationship, and save it in the $map array. For example, the adopt field value is not equal to 2 or type_id is equal to 24.
Then set the first query condition and the second query condition to be "AND" relationship through _complex.
In the is_power function, use find() to query data that meets the conditions, and use getLastSql() to output the generated sql.
Open the file execution controller in the browser and view the generated sql.
Summary:
1. In the thinkphp controller, the second query condition cooperates with _logic to set the logical relationship.
2. The relationship between the first query condition and the second query condition uses _complex to realize the logical relationship of "AND". thinkphp
Notes
The second query condition must be defined in a new array.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to query with multiple conditions in thinkphp. For more information, please follow other related articles on the PHP Chinese website!