php - Echo out the sum of a MYSQL column -


pretty simple script here working. echoing entire mysql query except sum total of donations. want echo out total donations 1 user, not donations.

here script.

<?php require_once("models/config.php");    $id=$_server['query_string'];  $sql = "select persons.personid, persons.firstname, persons.surname, donations.amount,     sum(donations.amount), donations.donation_type, donations.donation_date, donations.event persons, donations persons.personid = donations.personid = '$id' order personid";  $results = $mysqli->query($sql);   echo "<table border='1' cellpadding='10'>";     echo "<tr> <th>first name</th> <th>surname</th> <th>donation type</th> <th>donation     amount</th> <th>donation event</th> <th>donation date</th></tr>"; if($results->num_rows) { while($row = $results->fetch_object()) { echo "<tr>";             echo '<td>' . $row->firstname . '</td>';             echo '<td>' . $row->surname . '</td>';            echo '<td>' . $row->donation_type . '</td>';            echo '<td>' . $row->event . '</td>';            echo '<td>  $'.$row->amount. '</td>';            echo '<td>' . $row->donation_date . '</td>';   echo "</tr>";   echo "</table>";     echo $row->sum(amount); } } else { echo "</table>";   echo 'no results'; }  ?> 

i error code: "fatal error: call undefined method stdclass::sum() in ..." trouble - mysql query, php echo? need query total (something don't want do)?

thanks in advance.

in query give name column

sum(donations.amount) sum_amount 

then print echo $row->sum_amount


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -