在PHP中循环插入查询 [英] Loop over an insert Query in PHP
本文介绍了在PHP中循环插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在通过PHP脚本在SQL中插入相同的N次值时遇到麻烦. 我有这个vslue吗?
I am having trouble with insert the same value N time In SQL via PHP script. I have this vslue?
Table Info column (ID,Name, LastName,)
Valus ('',Alain,Alian);
我要做的是将此值插入到同一表中10次使用While循环进行E.G 或类似的东西 有什么主意吗?
Whata i want to do is insert this value in the same table 10 Times Using a While loop for E.G Or something like that any idea?.
<?php
$i=1;
While ($i<= 5)
{
$sql="INSERT INTO arivage
(ID_Ship,Date_ariv,Date_achat,prov_id,Sph,cyl,Prod_type,Pord_color)
VALUES
('','$date','$date1','$prov_id','$sph','$cyl','$Prod_type','$Pord_color')";
$i++;
}
?>
推荐答案
您有一些错误吗?
您需要什么是可行的
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
for($i = 0; $i<10; $i++) {
$sql="INSERT INTO arivage (ID_Ship,Date_ariv,Date_achat,prov_id,Sph,cyl,Prod_type,Pord_color) VALUES ('','$date','$date1','$prov_id','$sph','$cyl','$Prod_type','$Pord_color')";
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
这篇关于在PHP中循环插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文