MySQL结果资源无效

MySQL结果资源无效

我有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/

10-11 05:22