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 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to count number of records found in a database table?’ is closed to new replies.