...

View Full Version : Check if field contains, not equals, search word



tednkie
02-19-2012, 09:42 PM
Hi,

This is how a code snippet from my search function. Now it checks if $city is exact alike the different fields. Is there an easy way to check if $city (the search word/phrase) contains (not equals) anything in the "hotelname" field?


FROM citylist WHERE cityname='$city' OR local_citynames='$city' OR hotelname='$city' ORDER BY $order $ord LIMIT 30

Would really appreciate any help at all! :)

kbluhm
02-19-2012, 10:14 PM
Have a look at MySQL's LIKE operator (http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like).

Change
hotelname='$city' to
hotelname LIKE '%$city%'

tednkie
02-19-2012, 10:18 PM
Perfect! That worked nicely. Thanks a lot! :)

And thanks for the link.

qeemat
02-20-2012, 12:12 PM
Check this link for Complete searching functionality in php
http://youhack.me/2010/04/28/creating-a-fancy-search-feature-with-php-mysql-and-jquery/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum