Page 1 of 1
Search box with preg_match
Posted: Wed Sep 24, 2008 9:23 pm
by jeaux
If I'm doing a recipe site with a MySQL DB is preg_match the way to go? The table will be setup with recipe_id, recipe_name, recipe_description, and recipe_location. Every search I run on a search box only yields people talking about using a Google API.
Many thanks,
Joe
Re: Search box with preg_match
Posted: Thu Sep 25, 2008 12:56 am
by GeertDD
PHP's preg_match() does not really seem like an option to me. You would have to fetch all the records first, then loop through them all and use preg_match() to determine a match or not. An inefficient process.
Instead you can do the regex at the SQL level. MySQL has a
REGEXP filter.
Re: Search box with preg_match
Posted: Thu Sep 25, 2008 1:18 am
by jeaux
Thank you so much. I needed an investigative lead. Efficiency is my goal but as a noob some ideas just seem unattainable.