gpt4 book ai didi

php - 将 2 个数组值插入 mysql 数据库

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:05:32 25 4
gpt4 key购买 nike

我从我的 html 表单中获取了 2 个字段,它们将值存储在一个数组 中。

$ingredients = $_POST['ingredients'];
$quantity = $_POST['quantity'];

我想将这 2 个值插入到我的 mysql 数据库中。所以我正在使用以下内容:

foreach($ingredients  as $in)
{
foreach($quantity as $q)
{
echo "Intredent and quantity is : $in and $q<br/>";

//$insert = my mysql Insert query;
}
}

但它显示了两倍的值(value)。例如:如果它是 2 个值,则它显示 4 个值.. 等等。

最佳答案

foreach($ingredients as $key => $in)
{
echo "Intredent and quantity is : $in and $_POST['quantity'][$key]<br/>";
}

你想这样做吗?每种成分的数量?

关于php - 将 2 个数组值插入 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21347062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com