phparraysdatabaseintegerredbean

Array converted to int


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


Solution

  • 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.