Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if field contains, not equals, search word

    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?

    PHP Code:
    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!

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Have a look at MySQL's LIKE operator.

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

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect! That worked nicely. Thanks a lot!

    And thanks for the link.

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check this link for Complete searching functionality in php
    http://youhack.me/2010/04/28/creatin...ql-and-jquery/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •