使用多个数组保存多行 - PHP
我在将具有多个数组的多行保存到 MYSQL 中时遇到一个大问题。例如,第 1 行包含“名称”和“份额百分比”。然后他们添加另外 2 行,其中包含与上述相同的属性。那么如何将这些数据保存到DB中呢?下面是我不成功的代码:
foreach($_POST['name_members'] as $dir){ // array 1
$directorID = run_num('director_id','proc_director'); // generate running number for each row
foreach($_POST['share_percentage'] as $share) { //array 2
$insDirector = "INSERT INTO
proc_director(director_id, vendor_cd, director_name, director_percentage)
VALUES
('$directorID','$vendorID','".trim(addslashes($dir))."','$share')";
$db->query($insDirector); // save the array value into DB
}
}
我做了一个演示界面,这样你就可以得到我想要的图片。这里是超链接:http://softboxkid.com/blog/code/add_row/
I have a big problem on saving multiple rows with multiple arrays into MYSQL. For example row 1 contains "name" and "share percentage". Then they add another 2 rows which contains same attributes as mentioned. So how do I save these data into DB. Below was my unsuccessful code:
foreach($_POST['name_members'] as $dir){ // array 1
$directorID = run_num('director_id','proc_director'); // generate running number for each row
foreach($_POST['share_percentage'] as $share) { //array 2
$insDirector = "INSERT INTO
proc_director(director_id, vendor_cd, director_name, director_percentage)
VALUES
('$directorID','$vendorID','".trim(addslashes($dir))."','$share')";
$db->query($insDirector); // save the array value into DB
}
}
I made demo interface, so that you can get the picture what I want. Here the hyperlink: http://softboxkid.com/blog/code/add_row/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢您的回复。我已经找到了我的问题的解决方案。这是我的代码:
Thank for your respond. I already found the solution for my problem. Here is my code: