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