How to deal with multi-condition dynamic filtering

Source: Internet
Author: User
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 );}

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.