0

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;

        }

    }
BenMorel
  • 34,448
  • 50
  • 182
  • 322
fefe
  • 8,755
  • 27
  • 104
  • 180

1 Answers1

0

You have to use $wpdb to get number of rows

$this->wpdb->num_rows;
nikunj gandhi
  • 779
  • 5
  • 6