我一直在尝试在wordpress中编写一个mysql查询,但它似乎不起作用。 代码:
foreach ($postList as $curpostid) {
echo "postID ".$curpostid." + ";
$sql2 = 'SELECT * FROM wp_mr_rating_item_entry WHERE post_id='.$curpostid;
$results2 = $GLOBALS['wpdb']->get_results($sql2) or die(mysql_error());
}
$ postList打印为:
Array
(
[0] => 3148
[1] => 3097
[2] => 3048
[3] => 1036
)
这些帖子确实存在,回声显示它们很好。如果我输入$ curpostid的特定值作为查询之一的数组条目。看来查询不接受数组中的变量。 我已经尝试将变量设置为int(int)$ curpostid,因为字段类型是bigint但仍然不起作用。 任何帮助表示赞赏。
我已设法将输出放在多维数组中,但现在我无法将值放在一个数组中: 这是数组:
Array
(
[0] => Array
(
[0] => stdClass Object
(
[rating_item_entry_id] => 1
)
[1] => stdClass Object
(
[rating_item_entry_id] => 2
)
[2] => stdClass Object
(
[rating_item_entry_id] => 3
)
[3] => stdClass Object
(
[rating_item_entry_id] => 4
)
[4] => stdClass Object
(
[rating_item_entry_id] => 5
)
[5] => stdClass Object
(
[rating_item_entry_id] => 6
)
[6] => stdClass Object
(
[rating_item_entry_id] => 7
)
[7] => stdClass Object
(
[rating_item_entry_id] => 8
)
)
[1] => Array
(
[0] => stdClass Object
(
[rating_item_entry_id] => 10
)
)
[2] => Array
(
[0] => stdClass Object
(
[rating_item_entry_id] => 11
)
)
[3] => Array
(
[0] => stdClass Object
(
[rating_item_entry_id] => 14
)
)
)
如何将所有最终的rating_item_entry_id值放在一个数组中? 试过以下代码,但我有点困惑,它不起作用。
foreach($results2Array as $result2) {
foreach($result2 as $res2) {
echo $res2['rating_item_entry_id'];
$ratingentries[] = $res2['rating_item_entry_id'];
}
}
答案 0 :(得分:0)
试试这个:
foreach ($postList as $curpostid) {
$sql2 = "SELECT * FROM wp_mr_rating_item_entry WHERE post_id='".$curpostid."'"; //change here
$results2 = $GLOBALS['wpdb']->get_results($sql2) or die(mysql_error());
}