Search code examples
phpsqlarraysarr

PHP cant show result from SQL


I have a problem with sql. I am trying echo my SQL result but its not showing with my code. How can I echo 35000 and also convert this Thousand K like 35K? Thanks

$billings_sum = $wpdb->get_results( "SELECT SUM(bl_currency) from billings WHERE bl_user = '$user_id'" );

var_dump($billings_sum[0]);

I am trying with this code.

echo $billings_sum[0]["SUM(bl_currency)"];

Var_dump result:

object(stdClass)#709 (1) {
  ["SUM(bl_currency)"]=>
  string(5) "35000"
}

Solution

  • You can use Curly brackets like {} follow the below code

    echo $billings_sum[0]->{'SUM(bl_currency)'};
    

    Hope it will work.