我有 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);
有什么想法或建议吗?谢谢。
最佳答案
$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).')';
关于mysql - Wordpress MySQL 结果资源无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17408812/