php将数组存入sql,将PHP数组存储在单个SQL单元中

我希望在我的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,但这会增加新的成分

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值