我希望在我的SQL数据库中将项目作为数组或类似数据类型存储,并且无法找到关于该主题的令人满意的信息
在PHP中,信息将存储为成分[“$id”] = true或false,其中$id表示成分
所以对于普通面包(请注意,这仍然是伪代码,因为数据输入端尚未启动)
//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 '.';
这应该产生类似的东西
‘普通面包:小麦面粉,水,盐,酵母.
我查看了ENUM和SET,但这会增加新的成分