I try to get number of rows per query in my wordpress Class but I get each time null, what is wrong with the following
class MyClass{
private $wpdb;
private $query;
public function __construct(){
global $wpdb;
this->wpdb = &$wpdb;
}
public function build_query(){
//dynamic query will be build here, example
$this->query = 'SELECT id,name From my_table';
}
public function get_display_result(){
$res = $this->wpdb->get_results($this->query, ARRAY_A);
return $res;
}
public function get_total_results(){
$res = $this->wpdb->get_results($this->query);
$nr = $res->num_rows;
var_dump($nr);// I get NULL
exit();
return $res;
}
}
You have to use $wpdb to get number of rows
$this->wpdb->num_rows;