2

Can someone explain how I would output the result of the sql below? currently getting 'Object of class mysqli_result could not be converted to string'.

$sql = ("SELECT AVG(ab_satisfactionScore) AS AverageSatisfactionScore
     FROM tbl_appointmentsbooked;");

$result = mysqli_query($connection, $sql);

echo ($result);
Dharman
  • 30,962
  • 25
  • 85
  • 135
japes Sophey
  • 487
  • 3
  • 8
  • 26
  • When you're doing an echo on an object it looks for a magic method called `__toString()`, if it doesn't find that method it will throw an error. That's what's happening here. With that said, you need to get the results from the query, as it stands it returns an object. – Andrei Dec 10 '15 at 16:26

3 Answers3

1

Error because you are echoing an object, so try like this,

while($res = mysqli_fetch_array( $result )) {
    echo $res['AverageSatisfactionScore'];
} 
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
0

Use any of mysqli_fetch_*() functions (or in OOP style: $result->fetch_*()) to retrieve the results from the mysqli_results object ($results).

See mysqli_result documentation on the various methods and their uses.

Shadow
  • 33,525
  • 10
  • 51
  • 64
-1

because you try to use echo to print object, and it used to print string only, you should use:

print_f($result);

instead of

echo ($result);
Gouda Elalfy
  • 6,888
  • 1
  • 26
  • 38