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 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Removing number prefix

    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?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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?

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Good catch! Yes there will be numbers like that as well. I didn't account for that.

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    How about drop down menus instead of letting the user enter stuff?

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


    ------------
    Leonard Whistler

  • #5
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    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)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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?

  • #8
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by pcproff View Post
    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):


    Code:
    preg_match_all('#[a-z]+#i', $string, $matches);
    
    $sql = 'WHERE ingredient LIKE %'.$matches[0][1].'%';
    Last edited by MattF; 02-20-2010 at 10:48 PM.


  •  

    Posting Permissions

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