...

View Full Version : Removing number prefix



pcproff
02-19-2010, 10:10 PM
OK so i have recipes in a db and I want to remove anything that is

ie:

1 tbsp
3 tsp
etc etc.

I can add them as I run into them.

The reason behind this is I am creating a search bar and obviously a user would not input 1tbsp of salt they would just put in salt. So in other words I want to remove #'s and any strings that equal "tbsp","tsp" ?? Is my logic right?

mlseim
02-19-2010, 11:11 PM
What if the numbers are like,
1 1/2 tsp
1-1/2 tsp
1.5 tsp

or
1 to 2 cups of flour as needed.

Will there ever be anything like that?

pcproff
02-20-2010, 05:06 AM
Good catch! Yes there will be numbers like that as well. I didn't account for that.

Len Whistler
02-20-2010, 05:15 AM
How about drop down menus instead of letting the user enter stuff?

1 | tbsp | salt
3 | tsp | salt
1 | cup | sugar
2 | tsp | pepper


------------

pcproff
02-20-2010, 09:35 AM
Hey Len good idea but the user is just to insert the ingredient in the search bar. Milk, apple, ice. All my recipes are in a db with imeasurements of ingredients but do not want to input them again just to query the db for the search bar. That why I was hoping of removing any numerical and pre-defined string before it appears in the autocomplete of the search bar. Make sense?

JAY6390
02-20-2010, 01:01 PM
I don't understand why you need to remove the numbers. You can search a db for just salt etc using either the LIKE keyword with your words or a FULL TEXT search (see here (http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html))

mlseim
02-20-2010, 08:23 PM
You'll want each recipe to have the basic units (one serving), and then
if someone puts in 4 dinner guests, your script will automatically adjust
the recipe for four people (instead of one).

A database would contain all ingredients, with separate fields for the "base amounts".
So the numbers would be separate to begin with, you wouldn't need to separate them?

pcproff
02-20-2010, 10:28 PM
Jay,

Can you imagine adding every ingredient in the food world in there as a delimiter in that statement? That link seems like it already knows what the user is seraching for. As an autocomplete search bar I only want the autocomplete to show up with ingredients that match with what we have therefore, a sample db of every food in the world will not work.

MattF
02-20-2010, 10:40 PM
Can you imagine adding every ingredient in the food world in there as a delimiter in that statement? That link seems like it already knows what the user is seraching for. As an autocomplete search bar I only want the autocomplete to show up with ingredients that match with what we have therefore, a sample db of every food in the world will not work.

I doubt that's what he means. Parse the string for words and then use LIKE for the search. For example, (and this is only intended as an example):




preg_match_all('#[a-z]+#i', $string, $matches);

$sql = 'WHERE ingredient LIKE %'.$matches[0][1].'%';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum