Page 1 of 1

[FIXED] 1 search bar that searches 2 db fields

Posted: Tue Mar 31, 2009 1:48 pm
by ninethousandfeet
hello,
i currently have a search bar that will allow users to search any words in one field from my db (product_name). without adding another text field on the site, is there a way that my current search bar can search for words in two db fields(product_name and post_title)?

i know how to do this if i make a separate text field for each in the users window, but it would be a lot more convenient to have one search box.

any suggestions?

thank you!

Code: Select all

 
 <label for="product_name">Product(s) and/or Store Name:</label>
      <input name="product_name" type="text" id="product_name" size="40" />
 

Re: 1 search bar that searches 2 db fields

Posted: Tue Mar 31, 2009 9:01 pm
by tech603
Something like this would work,

Code: Select all

 
 
select * from yourTable where product_name LIKE '%your search word%' Or post_title LIKE '%yoursearch word%'
 
 
This will give return results for any thing that it finds that matches those two fields.

Hope that helps.

Re: 1 search bar that searches 2 db fields

Posted: Wed Apr 01, 2009 2:56 pm
by ninethousandfeet
thank you!