【发布时间】:2016-07-23 20:31:47
【问题描述】:
我有一个小问题....我不知道如何更正 INSERT 表中的所有数据,我尝试解释一下。例如,我在每个系统中插入 2 个 system_ids(1006,1011) 和 5 个 ids (1,3,4,19,18),例如:
=======================================
system_id | attribute_id | term_id
=======================================
1006 1 29
1006 3 29
1006 4 29
1006 19 29
1006 18 29
1011 1 29
1011 3 29
1011 4 29
1011 19 29
1011 18 29
我已经尝试过类似的方法,但这不能满足我的需要......
foreach ($sistemu_ids as $sistemos) {
foreach ($rez as $rezas) {
$wpdb->query("INSERT INTO " . $wpdb->prefix . "My_table
(system_id, attribute_id,term_id) VALUES ('$sistemos', '$rezas', '29')");
}
}
这段代码是这样插入的:
=======================================
system_id | attribute_id | term_id
=======================================
1006 1 29
1006 3 29
1006 4 29
1006 19 29
1006 18 29
1 29
3 29
4 29
19 29
18 29
【问题讨论】:
-
您的代码似乎没问题。有什么问题?
-
测试您的输入数据,因为 - eval.in/547335
-
尝试
print_r你输入数据并检查$sistemu_ids是否包含这两个值 -
谢谢,问题出在 $sistemu_ids 数组中 :-))
-
$sistemu_ids 可能在数组中包含一个空字符串或一个空值,生成与空 system_id 的第二次交互。解决首先清理数组或不要对无效值进行交互。
标签: php mysql wordpress foreach