0
$insert_additional_info=sprintf("INSERT INTO tbl_additional_info (productid,size_d,size_d1,bags,cartons,retail_price,sales_price,wholesale_price) VALUES (%s, %s,%s, %s,%s,%s,%s,%s)",
GetSQLValueString($product_id, "int"),
GetSQLValueString($size_d, "int"),
GetSQLValueString($size_d1, "int"),
GetSQLValueString($bags, "int"),
GetSQLValueString($cartons, "int"),
GetSQLValueString($retail_price, "int"),
GetSQLValueString($sales_price, "int"),
GetSQLValueString($wholesale_price, "int"));
而不是像上面插入,有没有一种方法,我可以在VALUES()内使用循环?可以在mysql查询中使用php for循环来插入数据吗?
原因是,我的输出或插入值是通过像这样循环生成的。
if(isset($_POST['submit']))
{
$_SESSION['myInputs_all'] = array($_POST["myInputs_d"],$_POST["myInputs_d1"],$_POST["myInputs_bags"],$_POST["myInputs_carton"],$_POST["myInputs_retail"],$_POST["myInputs_sales"],$_POST["myInputs_wholesale"]);
$counter = count($_POST['myInputs_d']);
$column_array=array('productid,size_d,size_d1,bags,cartons');
for($c = 0; $c < $counter; $c++)
{
foreach($myInputs_all as $all_inputs=>$value)
{
//This is the output
echo $value[$c];
}
}
}
现在,我该如何插入echo $ value [$ c];在INSERT QUERY的VALUES内部?
我试过下面的东西,但它说Query是空的。但这就是我想要解决的问题。
$insert_additional_info="INSERT INTO tbl_additional_info (productid,size_d,size_d1,bags,cartons) VALUES(";
$counter = count($_POST['myInputs_d']);
for($c = 0; $c < $counter; $c++)
{
foreach($myInputs_all as $all_inputs=>$value)
{
$insert_additional_info.=$value[$c];
$insert_additional_info.=")";
}
}
@ Arif_suhail_123,我这样做,但不是仅仅循环列它,通过行循环以及 – 2014-10-20 09:12:52
@ Arif_suhail_123,我不是很确定你如何想用的爆炸。看看编辑部分,这就是我想实现的。谢谢 – 2014-10-20 09:42:42
@ Arif_suhail_123,好的..没问题.. – 2014-10-20 09:57:53