coolphpdude Posted March 11, 2008 Share Posted March 11, 2008 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 https://forums.phpfreaks.com/topic/95592-text-search/ Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 Use Like $desc = $_POST['Desc']; "SELECT * WHERE Desc LIKE %".$desc."%"; Link to comment https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489359 Share on other sites More sharing options...
coolphpdude Posted March 11, 2008 Author Share Posted March 11, 2008 Thanks i'll give that a try right now Link to comment https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489415 Share on other sites More sharing options...
coolphpdude Posted March 11, 2008 Author Share Posted March 11, 2008 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 https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489432 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 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 https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489435 Share on other sites More sharing options...
coolphpdude Posted March 11, 2008 Author Share Posted March 11, 2008 your a star mate, works a treat! much appreciated!!!! Link to comment https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489448 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 welcome does the topic solved button exist anymore ? woohoo my 4,500 post! Link to comment https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489450 Share on other sites More sharing options...
coolphpdude Posted March 11, 2008 Author Share Posted March 11, 2008 Not sure, i've been looking for it but can't seem to find it! Link to comment https://forums.phpfreaks.com/topic/95592-text-search/#findComment-489452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.