Title: Database Count Query Not Returning Results
Last modified: August 20, 2016

---

# Database Count Query Not Returning Results

 *  Resolved [musichappens](https://wordpress.org/support/users/musichappens/)
 * (@musichappens)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/database-count-query-not-returning-results/)
 * Evening all,
 * I am having an issue with this particular query. It works for certain tables (
   like the users table), but not the one listed in the code. When I query the users
   table, it retrieves a number (the number of rows, as it’s supposed to). However,
   when I query the fm_data_1 table, it does not return anything.
 * I have tried everything I can think of, and cannot seem to get it to work. Any
   suggestions would be greatly appreciated!
 *     ```
       function displayText($rowCount){
       global $wpdb;
       $row = $wpdb->get_var( 'SELECT COUNT(*) FROM $wpdb->fm_data_1' );
       echo "The count of rows is {$row}";
       }
   
       add_filter('the_content','displayText');
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [musichappens](https://wordpress.org/support/users/musichappens/)
 * (@musichappens)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/database-count-query-not-returning-results/#post-3502168)
 * Let me also say that the users table is the one created by WordPress. The fm_data_1
   table was created by a plugin.
 *  Thread Starter [musichappens](https://wordpress.org/support/users/musichappens/)
 * (@musichappens)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/database-count-query-not-returning-results/#post-3502173)
 * Figured it out! Had to include this snippet of code to define the custom table
   in the class:
 * `$wpdb->fm_data_1 = $wpdb->prefix.'fm_data_1';`

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Database Count Query Not Returning Results’ is closed to new replies.

 * 2 replies
 * 1 participant
 * Last reply from: [musichappens](https://wordpress.org/support/users/musichappens/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/database-count-query-not-returning-results/#post-3502173)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
