PHP MySQL search with multiple criteria -


I have a search form in a website and there are several search terms that the user has input to do DB search The following terms in the form:

  • Keywords
  • for property (sales, fare ...)
  • Type of property (apartment, roof)
  • Maximum value

    is the script to search with the input of the above word < Pre> public function Do not get_property_list_by_search ($ start, $ per_page, $ keyword, $ prop_for, $ min, $ state, $ ptype, $ max, $ mysqli) {if (empty ($ start) & empty ($ per_page)) {return 0;} $ Start = preg_replace ('/ [^ 0-9] /', '', $ mysqli- & gt; real_cape_string ($ start)); $ Per_page = preg_replace ('/ [^ 0-9] /' , '', $ Mysqli- & gt; real_cape_string ($ per_page)); $ keyword = $ mysqli- & gt; real_escape_string (stripslash (keyword $)); $ prop_for = $ mysqli- & gt; real_escape_string (stripsSash ($ prop_for )); $ State = $ mysqli- & gt; Real_space_string (stripsashash ($ state)); $ ptype = $ mysqli- & gt; Real_scape_string (stripsSash ($ ptype)); $ Min_price = self :: num_clean ($ mysqli- & gt; real_escape_string ($ min)); $ Max_price = self :: num_clean ($ mysqli- & gt; real_cape_string ($ max)); $ T1 = ''; $ T2 = ''; $ T3 = ''; $ T4 = ''; $ T5 = ''; If (isset ($ keyword) & amp; amp; amp;! Empty ($ keyword)) '$' as in {$ t1 = "and` proj_title`. $ Keyword. '%' Or 'proje_addr` like'% ' '%' Like '%' or `proj_area` $ Keyword. "% '"; } If (isset ($ prop_for) & amp; amp;! Empty ($ prop_for)) {$ t2 = "and` proj_for` = '" $ Prop_for. "'"; } If (isset ($ state) & amp; amp; amp; nbsp; ($ state)) {$ t3 = "AND` state` = '" $ State. ""; } If (ezate ($ PTP) & amp; amp; low ($ PTP)) {$ t4 = "AND` proj_cat` = '" $ ptype. "'; } // minutes & amp; Maximum if ((isset ($ min_price) & amp; amp; amp; amp; amp; amp; nbsp; ($ min_price) & amp; amp; amp; (isset ($ max_price) & amp; nbsp; ($ max_price)) & quot; $ t5 = in between '". $ Min_price "' And '". Max_price. "'"; } // only if (! Empty ($ min_price) & amp; empty ($ max_price)) {$ t5 = "and` value` & gt; = '". $ Min_price. "'"; } // Maximum only (empty ($ min_price) & amp; amp; amp; empty ($ max_price)) {$ t5 = "and` value` Query ("SELECT * FROM 'project` WHERE` condition` =' 1 '"$ t1." ". $ T2." ". $ T3." "$ T4." ". $ T5." "" Order Followed by "DESC limit". $ Start. ",". $ Per_page); if ($ sql-> num_rows> 0) {return $ sql;} other {return false;}} The query output will be something like this:

      SELECT * FROM `project` WHERE 'proj_title' like '% keyword%' or` proj_addr` '% keyword%' or ' '250000' and '600000'  between '% keyword' and `proj_for` = 'sale' and` state` = 'somewhere' and `proj_cat` = '8' and 'price' as in proj_area` / Pre> 

    ( value is the datatype DCIA ML (10,2) , this stored value such as 250000.00 )

    However, the return result is not expected (not accurate), its price is also from 600000 More will come out with the project category which is outside of '8', which is not fancy

    Itemprop = "text">

    Instead of taking these variables you " = "Operator should be used.

      / * $ t1 = ''; $ t2 = ''; $ t3 = ''; $ T4 = ''; $ T5 = ' '; * / $ q = "Selecting * property from''````````````` need to include all ** or ** logical tests in Bracket // Most of the unsuccessful functions are also included Useless, // like you are starting multiple variables ($ keyword & amp; empty (keyword $)) {$ q = "AND" (`p_title '' like '". "Keywords."%' Or 'address Keywords like '% "Keywords like'% 'or' Territory ''% '. $ Keywords."%') "; } If ($ prop_for & empty ($ prop_for)) {// If you are using double quotes then you really do not have to handle the inclusion I $ Q. = "And` p_for` = '$ prop_for'"; } If ($ state & empty! ($ State)) {$ q = "AND` state` = '$ state'"; } If ($ ptype & amp;!! ($ Ptype)) {$ q = "and" p_category` = '$ ptype' "; } // only ($ min_price & amp; amp;! ($ Min_price)) {$ q = "and` value` & gt; = '" $ Min_price. "'"; } // maximum only ($ max_price & amp; empty ($ max_price)) {$ q = "and` value`  Query ($ q);    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -