gpt4 book ai didi

php - mysql_query() 插入过多数据

转载 作者:行者123 更新时间:2023-11-30 01:18:39 25 4
gpt4 key购买 nike

这是我的代码

for ($i=0;$i<1000;$i++)
{
if ($testArray[$i] != 0)
{
$sql = "insert into `dbTest`.`dbTable` (`colA`) values ('$input[$i]')";
mysql_query($sql);
}
}

如果我将浏览器中的结果复制到phpMyAdmin,数据将成功插入。但是当我使用函数 mysql_query() 插入时。每个数据都会被插入3次。另一方面,我有100条数据要插入,但是数据库会获取300条数据。如果您遇到类似的问题,请帮忙。谢谢^^

最佳答案

在 for 循环中尝试 sizeof:

for ($i=0;$i<sizeof($testArray);$i++)
{
if ($testArray[$i] != 0)
{
$sql = "insert into `dbTest`.`dbTable` (`colA`) values ('$testArray[$i]')";
mysql_query($sql);
}
}

关于php - mysql_query() 插入过多数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18799615/

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