Skip navigation
Scotster1
Currently Being Moderated

Beginner stumped, possible array solution?

Jul 31, 2012 11:08 AM

Tags: #cs5 #dreamweaver #list #ingredient

Hi there,

 

I am completely new to using anything other than frontpage for designing webpages so please bear with me

 

I've been experimenting with dreamweaver all week and it's just phenomonal. Of course through doing this I have gotten a taste of using PHP and Javascript, but I'm completely winging it and googling like a mad-un trying to find answers to, very simple, queries.

 

Anyway, here is what I am up to now...

 

I'm creating a very simple website that will host recipes. I have created the databases required etc but I can't fathom out how to dynamically attach a list of ingredients to a recipe.

 

Eg

 

Recipe name - WOW

Description - Home made wine

 

Ingredients | QTY

 

Sugar | 1000g

juice | 2L

water | 3L

 

Now for the main database I would like to have 5 columns, Recipe_No, Recipe_name, Recipe_Desc, Recipe_Ing and Recipe_qty.

 

I just have no idea how to do this. I'm guessing it would be an array? Obviously different recipes would have different amounts of ingredients so the array would need to be made dynamically depending on that.

 

Even just a nudge in the right direction would be great, I am a complete novice though and have only slightly dabbled with the code side of dreamweaver.

 

thanks

 

Scott

 

(Oh, sorry for the stupid username I got fed up with it refusing the names I was trying so I just typed in any old random key strokes)

 
Replies
  • Currently Being Moderated
    Jul 31, 2012 11:20 AM   in reply to Scotster1

    You would need at least two tables in your database. One to store the recipe name, number and description, and another to list the ingredients.

     

    And as an amatuer winemaker myself, I must ask that you do not actually publish that recipe

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 11:50 AM   in reply to Scotster1

    You should have 3 tables: recipes, ingredients, recipes_ingredients

     

    recipes should hold common things like id, name, description, etc

    ingredients should hold common things like id, ingredient, cost, etc

    recipes_ingredients would hold things like id, recipe_id, ingredient_id, qty

     

    You would then query the database and get all of the r_i and loop over that result set to display.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 1:12 PM   in reply to Scotster1

    >As you say I currently have 2 tables in my DB (that matter in this instance).

     

    You do, but as dunnmaks and I have already explained, you will need one that stores the ingredient id's used in each recipe.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 3:25 PM   in reply to Scotster1

    >or example if I had 3 ingredients with 20 recipes the

    >3rd table would have 60 entries. Seems like overkill to me.

     

    This is not overkill. This is the standard way to model the data. The 3rd table only needs to contain a few columns to identify, such as:

     

    1) The recipe_id

    2) The ingredient_id

    3) quantity used

     

    Don't worry about how many rows you are using. DBMS's are built to deal with extremely large amounts of data.

     

     

    >When a new recipe is created a variable array is made and the record is saved.

     

    When you store more than one piece of data into a single column, you are violating one of the most basic rules of data normalization.

     

    >The above is working for me at the moment using the implode and explode delimiters.

     

    Yes, you can get it to work but it's not a good practice and will make writing basic queries a big pain. Plus, how would you store recipe specific ingredient data, like quanity used?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points