Skip to main content
Participant
July 31, 2012
Question

Beginner stumped, possible array solution?

  • July 31, 2012
  • 1 reply
  • 833 views

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)

This topic has been closed for replies.

1 reply

Participating Frequently
July 31, 2012

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

Scotster1Author
Participant
July 31, 2012

Lol no worries about the recipe

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

The ingredient table looks like this..

ingr_no, ingr_name, yield, fermentability, ingr_cost, per_qty, ingr_unit

It's populated with only a few items to get me started.

The recipe table looks like this...

recipe_no, recipe_name, recipe_desc, recipe_ingr, ingr_qty, recipe_proc... etc

Everything is very simple to populate other than the "recipe_ingr" (and ingr_qty but that will be exactly the same) as obviously each recipe will have a number of ingredients. My problem is that I have no idea how to create an array dynamically based on a table of unknown quantity. My thinking is that all I really need to store in the "recipe_ingr" is the "ingr_no" of each item, as all the other information will be populated from it via the ingredients table.

I'm looking to use a dropdown to select the ingredient. When it's selected it's automatically added to the "recipe_ingr" array and the recordset will then update on the screen showing this. But I'm not sure what to write in order to have this action happen.

I'm possibly in over my head here as I'm even finding it hard to describe what I'm after lol.

Participating Frequently
July 31, 2012

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.