Ive made a search function and got it working, but I have 1 problem: If I input 1 word (lets say "test") it works fine and finds the row containing "test". But if I input "test something else" it dosent find anything.
How do I make the script search for each individual word in $_POST['search'] ??
Here's my code:
$itemOutput = '';
$dbhandle = mysql_connect('host', 'name', 'pass') or die("Unable to connect to MySQL");
$selected = mysql_select_db('my_website_db', $dbhandle) or die("Could not select database");
$search_term = mysql_real_escape_string($_POST['search']);
if (!isset($search_term) || $search_term == '' || $search_term == ' ' || !ctype_alpha($search_term)) { $result_count = "0"; } else {
$fetch_items = mysql_query("SELECT * FROM products WHERE name LIKE '%{$search_term}%' OR short_info LIKE '%{$search_term}%'");
while($shop_items = mysql_fetch_array($fetch_items)) {
$item_id = $shop_items['id'];
$item_name = $shop_items['name'];
$item_price = $shop_items['price'];
$item_image = $shop_items['image']; }
$itemOutput .= '<div class="item-box"> <img src="'.$item_image.'" class="item-image" />';
$itemOutput .= '<div class="item-price"> <a style="padding-left: 15px; font-size: 14px; padding-top: 3px;">Kun </a> <a><b>'.$item_price.' kr.</b></a> </div> <br>';
$itemOutput .= '<div class="item-name"> <a>'.$item_name.'</a> </div> <br>';
$itemOutput .= '<a href="vare.php?id='.$item_id.'"><button class="item-button">Køb her ></button></a> </div>';
}
EDIT: Thanks to all the inputs, I just got it to work :)