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 6 of 6

Thread: using LIKE

  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts

    using LIKE

    I rarely use LIKE so just wanted to verify this is correct, it seems to work..

    $searchsql is the field name, choice of several
    $searchforthis is what they entered into the input.

    The wildcard % needs to be on both sides to truly be wild right.


    PHP Code:

    $query
    ="SELECT * FROM recipes WHERE $searchsql LIKE '%$searchforthis%' AND rec_approved = 1 ORDER BY $searchsql"

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    That's right.
    "truly wild" searches though also can't be indexed, so as your recipes grow, the time it takes to search will also grow accordingly. If you use a BEGINS with type approach for the criteria instead of the CONTAINS approach, then you can index it.

  • Users who have thanked Fou-Lu for this post:

    durangod (12-13-2012)

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    Thanks, it is a male oriented site and i just added the recipes page as a favor to one of the female members so i dont see alot of data being entered like it would on a purely recipe site. Not that men dont cook but you get my drift.

    I would be very surprised if there are even a couple hundred in the next 5 years. So i dont see a huge issue with searches unless it starts getting into the thousands of records.

    Thanks so much.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    As long as we can find "cakes" and "takeaways" I'll be happy
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by durangod View Post
    Thanks, it is a male oriented site and i just added the recipes page as a favor to one of the female members so i dont see alot of data being entered like it would on a purely recipe site. Not that men dont cook but you get my drift.

    I would be very surprised if there are even a couple hundred in the next 5 years. So i dont see a huge issue with searches unless it starts getting into the thousands of records.

    Thanks so much.
    I hella bake, but don't consider myself less of a man for doing so. I'm not a great cook though. . .
    Regardless, the same applies to any table search. If you search for a user that contains 'AC' in their name, you need to check every record to see if its true (%AC%). As opposed to searching for someone who's name begins with AC (AC%) which can be indexed. So you should be careful with containment searches and use the sparingly if you can get away with a begins with. In the web world that's often a simple matter of having a search box with a drop down next to it that gives the options for begins with and contains. Default to begins with and at least most of the work would be done using a begins with search.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    But if you have no choice about using %AC% and if things start bogging down, look into Full Text searches.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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