I want to store the ingredients if the element as an array or similar data type in my SQL database, and can not find satisfactory information on this
In PHP, information will be stored as ingredient["$id"]=true or false , where $ id is a component
So, for plain bread (note that this is basically a pseudo code, since the data entry side is not running yet)
//code that creates array this bit is still theory and will be manually emulated in the db for the time being $id=1; while (isset ($_POST["ingredient part of form".$ID])){ if ($_POST["ingredient".$id]==checked){ $p["ingredient"][$id]=true; } else{ $p["ingredient"][$id]=false } $id++; } //the code that gets the values back for the ingredient name we will use a separate array ingredient_n[$id] echo p[$prod_id]["item"].': ' $id=1 while (isset ($ingredient[$id])){ if ($p[$prod_id]["ingredient"][$id]==true) if ($id!=1){ echo ', '; } echo $ingredient_n[$id]; } } echo '.';
This should produce something like
"PLASMA BREAD: WHEAT, WATER, SALT, YEAR."
I looked at ENUM and SET, but that would make it harder to add new ingredients
Hector James Haddow
source share