How to parse value from wordpress $wpdb->get_results()?

I am working on wordpress theme and failed to use arithmatics operation on wpdb->get_results().

If i write simple, then it update sucessfully in database

Read More
$sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";

    $result = $wpdb->get_results($sql) or die(mysql_error()); 


    $calc = $result;

But if I use minus operation with result it throws fatal error.

$sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";

    $result = $wpdb->get_results($sql) or die(mysql_error()); 


    $calc = $result - 1;

Error

Fatal error: Unsupported operand types in C:xampphtdocsbetawp-contentthemesbyt-childincludespost_typesaccommodations.php on line 1199

Freinds please suggest me how to resolve this. I have used result->room_count -1 but stucked on result.

Related posts

Leave a Reply

1 comment

  1. If you are expecting a single result field, you should use get_var

    $sql = "SELECT room_count from " . BOOKYOURTRAVEL_ACCOMMODATION_VACANCIES_TABLE . " where accommodation_id = $accommodation_id";
    
    $result = $wpdb->get_var($sql); 
    
    if( $result ) {
        $calc = $result - 1;
    }