no result returns when using $wpdb->get_results with where clause

Question

I have 2 mysql queries, 1 with where clause, 1 without where clause. The one with where clause is not able to generate results eventhough the query is correct, I have tested it on PhpMyadmin.
Meanwhile the one without where clause works just fine.
How to solve this problem?

$query = "select distinct u.ID, u.display_name, u.user_email, s.status_description, m.membership_description, c.nicename from ".$wpdb->prefix ."users u left outer join wp_usermeta um on u.ID=um.user_id left outer join user_extension ex on u.ID=ex.wp_users_ID left outer join user_status s on ex.userstatus_id=s.userstatus_id left outer join memberships m on ex.memberships_membership_id=m.membership_id left outer join country c on ex.country_id=c.id left outer join learners l on u.ID=l.wp_users_ID ";
        
        if(isset($placeholders) && !empty($placeholders)){
            $query = $query . $where;
            $sql = $wpdb->prepare($query,$placeholders);
            
            $users = $wpdb->get_results($sql); //return empty array
        }
        else{
            $users = $wpdb->get_results($query);
        }
        echo "users=" . print_r($users, true) . "<br><br>";

0
Murniyanti Malik 1 month 2021-05-05T00:48:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse