Quantcast
Viewing all articles
Browse latest Browse all 8245

hitu165 on "How to count number of records found in a database table?"

I am new to WordPress development & tried to learning plugin development.I have created a custom table from which i want to show the number of records found.I have tried the below code but it always shows 1 as a result irrespective of number of rows in a table.

//To show number of rows in table
function DB_Tables_Rows()
{
global $wpdb;
$table_name = $wpdb->prefix . 'mydata';
$count_query = "select count(*) from $table_name";
$num = $wpdb->get_var($count_query);

$num = $wpdb->num_rows;

echo $wpdb->num_rows . 'Rows Found';

}


Viewing all articles
Browse latest Browse all 8245

Trending Articles