[FIXED] 1 search bar that searches 2 db fields

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

[FIXED] 1 search bar that searches 2 db fields

Post 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" />
 
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: 1 search bar that searches 2 db fields

Post 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.
ninethousandfeet
Forum Contributor
Posts: 130
Joined: Tue Mar 10, 2009 4:56 pm

Re: 1 search bar that searches 2 db fields

Post by ninethousandfeet »

thank you!
Post Reply