Dear nachgeist03,
Before tackling the web-interface, let's first do a definition of the data-base structure that you need.
You need a data-base table that contains a row for every fruit that you want to describe.
The columns of that "
fruits" data-base table would be:
(1) id (identification) - type=integer - autoincrement (means that the data-base engine will generate a value for this field, automatically, when the row is inserted into the data-base table "
fruits".
(2) name (the fruit's name) - type=text
(3) color_id - type-integer - this field will contain the identification number of the row in the "
colors" data-base table that contains the information about fruit colors.
Because we talked about a new data-base table, "
colors", let's describe this tables.
The columns of the "
colors" data-base table would be:
(1) id (identification) - type=integer - autoincrement (means that the data-base engine will generate a value for this field, automatically, when the row is inserted into the data-base table "
colors".
(2) name (the color's name) - type=text
(3) description (the color's long description) - type=varchar
We will need a web-dialog that allows us the enter the different colors, and their long description.
The columns of the "
recipes" data-base table would be:
(1) id (identification) - type=integer - autoincrement (means that the data-base engine will generate a value for this field, automatically, when the row is inserted into the data-base table "
recipes".
(2) name (the recipe's name) - type=text
(3) description (the recipe's long description) - type=varchar
We will need a web-dialog that allows us the enter the different recipes, and their long description.
And yet another data-base table is needed.
This data-base table will be the link between the "
fruits" and the "
recipes" data-base tables.
The columns of the "
fruits_recipes" data-base table would be:
(1) id (identification) - type=integer - autoincrement (means that the data-base engine will generate a value for this field, automatically, when the row is inserted into the data-base table "
fruits_recipes".
(2) fruit_id - type=integer - this field will contain the identification number of the row in the "fruits" data-base table that contains the information about fuits.
(3) recipe_id - type=integer - this field will contain the identification number of the row in the "recipes" data-base table that contains the detailed information about fuit cooking recipes.
Why did we separate our information into 4 data-base tables?
This was done because of the rules of relational data-base design:
when an information occurs more than once, it must be moved into a separate data-base table.
This is know as "normalizing".
Indeed, more than one fruit may be "red", and more than one fruit may be used in the same recipe, for instance "apple pie with raspberry topping".
The "
fruits" data-base table would be:
id=1 - name=orange -
color_id=4id=2 - name=raspberry -
color_id=6id=3 - name=apple -
color_id=5id=4 - name=strawberry -
color_id=6The "
colors" data-base table would be:
id=1 - name=black - description=blabla...
id=2 - name=white - description=blabla...
id=3 - name=blue - description=blabla...
id=4 - name=orange - description=blabla...
id=5 - name=green - description=blabla...
id=6 - name=red - description=blabla...
The "
recipes" data-base table would be:
id=1 - name=Apple pie with raspberry topping - description=The recipe is as follows:.......
The "
fruits_recipes" data-base table would be:
id=1 -
fruit_id=2 -
recipe_id=1id=2 -
fruit_id=3 -
recipe_id=1Now that the information is stored into separate tables, it has become very easy to use PHP to generate the drop-down boxes for the web-interface.
We simply query the data-base table
colors and obtain all
valid colors, alfabetically.
SQL
select id,name from colors order by name;
(The same would be true for supplemental information, like the month that the fruit is available. Just create a separate data-base table, and insert a new column in the "
fruits" data-base table.)
The generated HTML would be:
HTML
<SELECT NAME="mycolor">
<OPTION VALUE="1">black
<OPTION VALUE="2">white
<OPTION VALUE="3">blue
<OPTION VALUE="4">orange
<OPTION VALUE="5">green
<OPTION VALUE="6">red
</SELECT>
And the PHP that would be called could do the following SQL:
SQL
select name from fruits where color_id = $mycolor;
This would result in all fruits with the color that the surfer had selected in the dropdown box.
Moreover, the PHP could do the following SQL:
SQL
select recipes.name, recipes.description
from recipes,fruits,fruits_recipes where fruits.color_id = $mycolor and fruits_recipes.fruits_id = fruits.id and fruits_recipes.recipes_id = recipes.id;
This would result in all recipes with fruits that have the color that the surfer had selected in the dropdown box.
From here on, you can start designing your web-application...
Reply