Search multiple php words
UPDATE:
I got a little further:
$query = mysql_real_escape_string($_POST['search']);
$keywords = explode(" ", $query);
foreach ($keywords as $keys) {
$search_sql .= " AND Name LIKE '%$keys%' ";
}
But it still doesn't return anything.
I couldn't find it because I didn't know how to say it. Basically, when a user asks for my database, I want to return the card, but if the user missed one word that is in the middle (let's say he asks for Elesh Norn Foil, since they didn't ask for Elesh Norn, Grand Cenobite Foil for sure of Great Senobite disables my program and returns nothing).
So:
-John's like "Elesh Norn" he brings back "Elesh Norn, Grand Cenobite" and "Elesh Norn, Grand Cenobite Foil".
-When if Johnny calls "Elesh Norn Foil" he returns with "No card found!" match
Here's my request:
SELECT Name, Amount, CardID FROM modernmasters WHERE Name LIKE '%".$_POST['search']."%'
So should I change my query so that my search doesn't work?
+3
source to share
1 answer
Try it. Hope this helps.
$search_sql = "SELECT Name, Amount, CardID FROM modernmasters WHERE";
$query = mysql_real_escape_string($_POST['search']);
$keywords = explode(" ", $query);
$keyCount = 0;
foreach ($keywords as $keys) {
if ($keyCount > 0){
$search_sql .= " AND";
}
$search_sql .= " Name LIKE '%$keys%'";
++$keyCount;
}
+3
source to share