The SQL query counts the sum of the fields for a specific user ..

In phpMyAdmin, the result is:

SUM(square) 512 


 $s = "SELECT SUM(square) FROM reports WHERE username = '$str';"; $r = mysql_query($s); if ($r) { echo 'Запрос выполнен' ."<br />" ; $Result = mysql_fetch_array($r); $user = $Result[SUM(square)]; echo $user; } 

How to display the result of this query?

  • the question is closed - Anna

1 answer 1

Use an alias in the query: SELECT SUM (square) as sm FROM ...

This alias and use to refer to the column.

  • Or, since mysql_fetch_array () is still used, then: $ user = $ Result [0]; - Photon
  • Photon, of course, can also use a numbered array, but I responded to an error in using associative. - msi