Multi-condition dynamic filter Price: 100020003000 Time: 200120022003 clear price clear time all clear now point 1000 already has content, but MYSQL statement error, click 2001 again, the content that meets the two conditions has also come out, and the SQL does not prompt an error. $ Resultmysql_query (select * fromnews_cwheretitle. $ title multi-condition dynamic filtering
Price: 1000 2000 3000
Time: 2001 2002 2003
Clear price clear time clear all
Now there is content available at, but the MYSQL statement is incorrect. click 1000 again. The content that meets the two conditions also comes out, and the SQL does not prompt an error.
$ Result = mysql_query ('select * from news_c where title = '. $ title.' or f_id = '. $ f_id .'');
How to change the SQL statement does not cause errors because only one condition is clicked.
------ Solution --------------------
Dynamically assemble SQL strings based on the number of input parameters
------ Solution --------------------
Here is a test example.
PHP code
$ Jg = array (1000,200 0, 3000); $ sj = array (2001,200 2, 2003); if (isset ($ _ GET ['AC']) {$ k = substr ($ _ GET ['AC'], 3); unset ($ _ GET ['AC']); if ($ k = 'all ') $ _ GET = array (); else unset ($ _ GET [$ k]);} echo'
Price: '; $ param = getparam ('JG'); foreach ($ jg as $ v) echo "$ v"; echo'
Time: '; $ param = getparam ('SJ'); foreach ($ sj as $ v) echo "$ v"; $ param = http_build_query ($ _ GET); echo"Clear price clear time clear all "; echo"
Select * from tbl_name ". expr (); function getparam ($ k) {$ param = $ _ GET; if (isset ($ _ GET [$ k]) unset ($ param [$ k]); $ param [$ k] = ''; return http_build_query ($ param);} function expr ($ expr = 'and ') {if (! $ _ GET) return ''; foreach ($ _ GET as $ k => $ v) $ r [] =" $ k = '$ V '"; return 'where '. join ("$ expr", $ r );}