How can I use wildcard in the most efficient way?
I have a quick search bar code that I'm working on and it looks like this:
searchbar.php:
<form method="post" action="search.php">
<input type="text" name="search" />
<input type="submit" />
</form>
search.php:
<?php
include("config.php");
$search = mysql_real_escape_string($_POST['search']);
$data = mysql_query("SELECT * FROM shop WHERE name LIKE '%$search%' OR id
LIKE '%$search%' OR description LIKE '%$search%' OR keywords LIKE
'%$search%' ORDER BY id DESC ") or die(mysql_error());
while ($info = mysql_fetch_array($data)) {
$name = stripslashes($info['name']);
$desc = stripslashes($info['description']);
Print "<h3><a href=\"result.php?product=".$name."\">".$name."</a>:
<font color=\"#cd0000\">".$desc."</font></h3><br>";
}
echo $name;
?>
result.php:
<?php
$result = $_GET['product'];
echo $result;
?>
Now my question is with the wildcard in my search. Say somebody searches
two words, "foo bar." The way I have it the words have to be exactly in
that order with a space between them for something to come up. Is there a
way so that within my search parameters if the words "foo" and "bar" are
anywhere (even not next to each other) the result will show up? Also I
want it to work if the order of the words are reversed in order, "bar foo"
(once again even not next to each other).
No comments:
Post a Comment