Jump to content

Text Search


coolphpdude

Recommended Posts

Hi,

 

I need help on a project. Ive created a database where you upload details on a holiday (location, hotel, features of the hotel, price, etc...), so there are quite alot of fields. On the website i want to give the user a basic search facility. I want the user to be able to enter a single word or combination of words to search for matches within my database. So for example...

 

if i have got this record in my database:

Hotel: The Leazes

Rooms: 2

Description: Beautiful modern hotel with swimming pool and kids club.

 

If the user enters 'the leazes' it finds the hotel and displays the results, however, if the user searches for the word 'leazes' only then nothing is returned. Can any1 help with this?

 

Thanks

Link to comment
Share on other sites

Hi again, that hasn't worked for me. I'll copy my code in, the search variable is called $keyword

 


$holiday_result = mysql_query("SELECT * FROM holidays WHERE holiday_id='$keyword' OR holiday_hotel LIKE %'.$keyword.'% OR holiday_area='$keyword' OR holiday_location='$keyword' OR holiday_description='$keyword' OR holiday_price='$keyword' OR holiday_status='$keyword'",$db); 

 

The part of the search where it checks the holiday_hotel is the only part i have altered so far. The reason i have only altered this part of the code is because it is only the hotel that i am querying for test purposes the final search facility will do a 'LIKE' search within all fields.

 

Thanks again for your help

Link to comment
Share on other sites

should be

 

holiday_hotel LIKE '%".$keyword."%'

note the quotes

$holiday_result = mysql_query("SELECT * FROM holidays WHERE holiday_id='$keyword' OR holiday_hotel LIKE '%".$keyword."%' OR property_area='$keyword' OR property_city='$keyword' OR property_postcode='$keyword' OR property_price='$keyword' OR property_status='$keyword'",$db); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.