-1

I have a problem, I need to convert from an array to a full number, but I don't understand how. i`m using redbeanphp. Help please

print_r(R::getRow('SELECT SUM(view) FROM posts WHERE author LIKE ? LIMIT 1', ['dffdfghdfgdf']));

Result: Array ( [SUM(view)] => 27 )

if through echo, then it simply gives an error that it is an array.

Result: Warning: Array to string conversion in

Taras
  • 3
  • 3

1 Answers1

-1

You should print the value of the array element, not the array itself.

Also, you may use an alias for a result column using the as operator.

$result = R::getRow('SELECT SUM(view) as s FROM posts WHERE author LIKE ? LIMIT 1', ['dffdfghdfgdf']);
print_r($result['s']);

echo would work either in this case.

zavg
  • 10,351
  • 4
  • 44
  • 67