目前,当通过 print_r() 输出时,我有一个如下所示的数组;
Array
(
[0] => Array
(
[R_ID] => 32
[email] => a@a.com
[name] => Bob
)
[1] => Array
(
[R_ID] => 32
[email] => b@b.com
[name] => Dan
)
[2] => Array
(
[R_ID] => 32
[email] => c@c.com
[name] => Paul
)
[3] => Array
(
[R_ID] => 35
[email] => d@d.com
[name] => Mike
)
)
我想将此数据插入到一个表中,每个元素值属于其各自的字段。
目前我的 php 代码如下所示
if(is_array($EMailArr)){
foreach($EMailArr as $R_ID => $email => $name){
$sql = "INSERT INTO email_list (R_ID, EMAIL, NAME) values ('$R_ID', '$email', '$name')";
mysql_query($sql) or exit(mysql_error());
}
}
*注意:R_ID 不是此表中的主键。*
有人可以帮助我了解我应该如何处理这种情况吗?感谢您的阅读和您的帮助!
问候。