小编Hec*_*dow的帖子

将PHP数组存储在单个SQL单元中

我希望在我的SQL数据库中将项目作为数组或类似数据类型存储,并且无法找到关于该主题的令人满意的信息

在PHP中,信息将存储为ingredient["$id"]=true or 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]; …
Run Code Online (Sandbox Code Playgroud)

php mysql sql arrays

7
推荐指数
2
解决办法
8048
查看次数

标签 统计

arrays ×1

mysql ×1

php ×1

sql ×1