Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2012, 03:07 PM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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"
durangod is offline   Reply With Quote
Old 12-13-2012, 03:23 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
durangod (12-13-2012)
Old 12-13-2012, 03:36 PM   PM User | #3
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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.
durangod is offline   Reply With Quote
Old 12-13-2012, 05:26 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 12-13-2012, 05:28 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 12-13-2012, 08:10 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,226
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:22 PM.


Advertisement
Log in to turn off these ads.