Just like this, how to do multi-condition search?
Just like this, how to do multi-condition search?
Reply content:
Just like this, how to do multi-condition search?
Directly run the Code:
$ Query = []; $ valid = ['type', 'area ', 'Year', 'person']; // valid query Key: type/region/age/star foreach ($ _ get as $ queryName) {// when querying all, ignore this condition if ($ _ GET [$ queryName]! = 'All') & in_array ($ queryName, $ valid) {$ query [$ queryName] =_ _ GET [$ queryName];} $ where = count ($ query )? 'Where'. implode (',', $ query): ''; $ result = $ db-> query (" SELECT * FROM tableName {$ WHERE }");
These conditions are a classification.
The intersection under various categories is good.
Use the where statement in mysql and connect with and.
Concatenate SQL statements. Set an array $ search to save the submitted condition values. For example, $ search ['type'] = $ _ GET ['type'] assigns each condition a value once. Before splicing an SQL statement, you must determine each condition, for example, if ($ search ['type']) $ query. = 'AND type =? '; $ Bind [] = $ search ['type'];
Concatenate SQL statements when the conditions are not empty. Otherwise, the SQL statements are not concatenated.