我有 wp_places 自定义表格,当我打印数组时,我得到了这个:
[0] => stdClass Object
(
[home_location] => 24
)
[1] => stdClass Object
(
[home_location] => 29
)
现在我想以这种方式破坏价值(24,29)但是在我的代码中我收到了这个错误:
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
我的代码
$getGroupType = $_POST['parent_category'];
$result = $wpdb->get_results( "SELECT home_location FROM wp_places WHERE blood_group LIKE '".$getGroupType."%'" );
$bgroup = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bgroup[] = implode(',',$row);
}
echo implode(',',$bgroup);
有任何想法或建议吗?感谢。
答案 0 :(得分:5)
$wpdb->get_results()
已为您抓取,您无需拨打mysql_fetch_array
鉴于您想要做什么,您的代码应如下所示:
$getGroupType = $_POST['parent_category'];
$result = $wpdb->get_results( "SELECT home_location FROM wp_places WHERE blood_group LIKE '".$getGroupType."%'" );
$bgroup = Array();
foreach ($result as $location) {
$bgroup[] = $location->home_location;
}
echo '('.implode(',',$bgroup).')';
答案 1 :(得分:0)
这是一个包含结果的PHP对象,它不是MySQL结果。
查看docs,应该像
一样使用foreach ($result as $row) {
$bgroup[] = $row->home_location;
}
echo implode(',',$bgroup)