PHP Query comes back as ‘Array’ instead of a name from database

I have the following query:

$name = $wpdb->get_results("SELECT appname FROM `$table_db_name` WHERE ID = '$ID' ", OBJECT);

Every of these values are correct and when I query it to the database it returns me an array with 1 option.

Read More

When I echo $name its result is: ‘Array’, while in the database it says: ‘Succesful’

It should mention ‘Succesful test’ as echo and not ‘Array’

Related posts

Leave a Reply

1 comment

  1. Try this:

    Edit:
    Since i didn’t notice that you were using WordPress, one thing you can do.

    $result = $wpdb->get_row($wpdb->prepare("SELECT appname FROM $table_db_name WHERE ID= '$ID' "), OBJECT);
    if(!empty($result)){
      var_dump($result->appname);
    }
    

    You can also use $wpdb->get_var() instead of $wpdb->get_row() to fetch only the appname and not have to worry about using arrays.

    $app_name = $wpdb->get_var($wpdb->prepare("SELECT appname FROM $table_db_name WHERE ID =      '$ID' "), OBJECT);
    if(!empty($app_name)){
    var_dump($app_name);
    }
    

    more information found here:
    https://wordpress.stackexchange.com/questions/14239/wpdb-get-row-only-returns-a-single-row