Title: Return true if data is empty function.
Last modified: August 24, 2016

---

# Return true if data is empty function.

 *  [yadigit](https://wordpress.org/support/users/yadigit/)
 * (@yadigit)
 * [11 years ago](https://wordpress.org/support/topic/return-true-if-data-is-empty-function/)
 * I am trying to create a function that will draw data from the database and check
   if the row is empty. If the function is empty, continue.. If !empty, do not display
   anything. I know there is many ways to do this. But I am trying to create less
   code and structure it a little neater.
    Here is my example.
 *     ```
       function check_if_blocked(){
       global $wpdb;
       $results = $wpdb->get_results("SELECT * FROM 'mytable' WHERE user = $user");
       if(empty($resuts)){
          $var = false;
        } else {
          $var = true;
        }
       return $var
       }
   
       function msg_form(){
        if(check_if_blocked()){
         // do stuff if user is not blocked
         // If user is blocked, do not display code
        }
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [John Parris](https://wordpress.org/support/users/mindctrl/)
 * (@mindctrl)
 * [11 years ago](https://wordpress.org/support/topic/return-true-if-data-is-empty-function/#post-6151369)
 * Try something like this:
 *     ```
       function check_if_blocked(){
         global $wpdb;
         return $wpdb->get_results("SELECT * FROM 'mytable' WHERE user = $user");
       }
       ```
   
 *     ```
       function msg_form(){
         if( ! empty( check_if_blocked() ) {
         // do stuff
       } else {
         // don't do stuff
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Return true if data is empty function.’ is closed to new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [return](https://wordpress.org/support/topic-tag/return/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [John Parris](https://wordpress.org/support/users/mindctrl/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/return-true-if-data-is-empty-function/#post-6151369)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
