0

I have a database table with several columns:

Category               Model       Manufacturer
Roland Pianos    |     HP605  |    Roland
Kawai Pianos     |     CL36   |    Kawai
Roland Keyboards |     BK9    |    Roland

I want to be able to search both columns at the same time so when I put in the search bar Roland HP605 I want the result to show the Roland HP605.

At the moment I've got the following: Search Box:

<input id="search" name="Search" type="text" placeholder="Search Products">

Search Code:

if (isset($_GET['Search'])) {
$query_RS_Search ="SELECT * FROM products WHERE Category LIKE :search OR products.Manufacturer LIKE :search OR products.Model LIKE  :search";

$RS_Search = $conn->prepare($query_RS_Search) or die(errorInfo());
$RS_Search->BindValue(':search', '%'.$_GET['Search'].'%');
$RS_Search->execute();
$row_RS_Search = $RS_Search->fetch();

Which works fine if you put in the search bar "Roland" All Roland products come up both piano and keyboard, however if I search for "Roland HP605" it will not be able to find it.

Any help welcome

Ria
  • 516
  • 6
  • 24
  • You may need to split the search bar value into separate words & use a more complex query to combine them - some ideas here : http://stackoverflow.com/questions/11106888/using-or-in-like-query-in-mysql-to-compare-multiple-fields – PaulF Sep 24 '15 at 09:37

1 Answers1

0

Try this

SELECT * FROM products WHERE CONCAT(Category, products.Manufacturer,products.Model) LIKE :search 
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
  • Thanks for your reply, however that doesn't do the trick. It find it if you either put in Roland (all Roland Comes up) or HP605 only the HP605 comes up. But if you combine it like " Roland H605" it won't find any. – Ria Sep 24 '15 at 10:16
  • I have managed to solve the problem I had to explode the string and than use these like suggested in both replies from Rahautos and PaulF. So thanks for your help – Ria Sep 24 '15 at 11:05