search for multiple keywords with php and mysql (where X like) -
I have a code that dynamically searches for data using Ajax in database Can only search for 1 keyword. I would like to modify it so that I can find many keywords. Now, if I type 2 keywords different from one place and database, then the data is not separated from one location, there will be no results if the database has data:
' Playstation3 'or' play cool station3 '
and I searched for:
play station
any result Will not done. I would like to know whether it is possible to modify my code so that I can divide 2 or more keywords or words into one place or another word or a DOT or underscore or (-) or (+) or (%) . Or (some more worthy)
I know that I should use pedo or mysquely but I am using it only for testing!
$ queried = $ _POST ['query']; $ Search = mysql_query (like '% $% queried' from the 'Select * link);; while $ searche = mysql_fetch_array ($ search)) {echo "". $ Searche [' link ']. "& Lt ; / Br> ". $ Searche ['name']." & Lt; / Br> ". $ Searche ['size']" & lt; / Br> ". $ This search ['category']" & lt; Hour & gt; & Lt; / Br & gt; & Lt; / Br> "..}
To search all the keywords dynamically You can use the Exploding function to isolate all the keywords;
$ queried = mysql_real_escape_string ($ _ POST ['query']); // always $ keys = Escape from explosion ("", $ queried); $ Sql = "SELECT *" link where '% $' is the name of the query ''; Foreign Currency ($ Key of $ as Key) {$ sql. = "Or name '% $ k%'"; } $ Result = mysql_query ($ sql);
Note 1: Always save user input before using it in your query.
Note 2: Mysql_ * functions have been deprecated, use mascular or pdo as an option
Comments
Post a Comment