Mysql multi-condition query problem "select * from subcatalog WHERE name LIKE '% $ keywords %' and catalog = $ catalog order by rank $ rank limit $ pages, $ rows"
The preceding statement can be used to search for other data when the value of $ catalog is null. now, when the value of $ catalog is null, nothing is available in the list.
Reply to discussion (solution)
When $ catalog is empty
Catalog = $ catalog ORDER
It becomes
Catalog = ORDER
Apparently, a syntax error occurs.
Enclose $ catalog in quotation marks and write '$ catalog'
However, there is still a problem: only records with the catalog empty can be queried.
If you do not want this, do not write catalog = '$ catalog' when $ catalog is empty'
The and catalog = $ catalog condition is proposed to write a variable separately. when $ catalog is empty, the entire condition is empty...
The syntax is adjusted as follows:
If ($ catalog = '') {$ tiaojian ='';} else {$ tiaojian = "and catalog = $ catalog ";} $ SQL = "select * from subcatalog WHERE name LIKE '% $ keywords %' $ tiaojian ORDER BY rank $ rank limit $ pages, $ rows"