我的var_dump($ _ POST)看起来像这样:提取阵列列数据转换成插入语句
Click here to see the jpg [ITEMNO] =>数组 ( [0] => xyz_1 1 => xyz_2 [2] => xyz_3 [3] => xyz_4 )
[itemName] => Array
(
[0] => stool
[1] => couch
[2] => chair
[3] => seat
)
[price] => Array
(
[0] => 15
[1] => 60
[2] => 10
[3] => 5
)
[quantity] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
)
[total] => Array
(
[0] => 15.00
[1] => 60.00
[2] => 10.00
[3] => 5.00
)
我试图使动态发票脚本。
对于每个添加的行项目,都会向以下所有数组中添加另一个键值,目前有4行项目正在从前一页面转移到$ _POST数据,如您所见。
我不知道如何从这些数组访问键值,并将它们转换为可以将每个行项插入数据库的格式。
例如我想插入:
(item_id
,item_call
,price
,quantity
,total
)VALUES(xyz_1,粪便,15,1,15)
(item_id
,item_call
,price
,quantity
,total
)VALUES(xyz_2 ,长沙发,60,1,60)
(item_id
,item_call
,price
,quantity
,total
)VALUES(xyz_3,椅子,10,1,10)
(item_id
,item_call
,price
,quantity
,total
)VALUES(xyz_4,座椅,图5,1,5)
如何格式/以有序的方式提取从阵列的每个密钥值,其中它不会如果有1个订单项目正在购买或说50个,那么问题很重要? - >该脚本会将所有数据解析为合适的插入语句,例如正在购买的1种物品类型/已插入1个记录=>正在购买的50种物品类型/已插入50个记录。
感谢您的帮助。
完美的答案!如果我想继续使用它:foreach($ vals as $ indval){Myqli_query($ mysqli,“”)} =>? – superiorpancakes
没有得到你,有什么问题吗? –
我需要将这些数据分别插入到我的数据库的相应列中。我是否需要为每个数组插入查询运行foreach语句? (即我的问题是关于将这个数组数据插入到表格列表中) – superiorpancakes