0

I am attempting to perform the following query:

SELECT SUM(cash) AS total_cash FROM users

The query should give me back a SUM() of the total cash which I've paid out to users in the form of a field named total_cash.

My HTML/PHP is as follows:

<p class="cash_count">
$<? 
    $total_cash = $db->GetNumRows($db->Query("SELECT SUM(cash) AS total_cash FROM users"));
    echo number_format($total_cash);
?>
</p> paid out!

I know GetNumRows will always show 1 as there's only 1 row, but I don't know what to use instead, can anybody guide me?

2 Answers 2

1

You are using some class to connect to database - you have not specified anything about that class. If $db->Query() returns the actual mysql resource, you can do this:

$res=$db->Query("...."); 
$r=mysql_fetch_object($res);
echo $r->total_cash;
Sign up to request clarification or add additional context in comments.

Comments

0

Yes, there's only 1 row, because your query ask for the SUM, and returns only 1 row with the sum.

You can do 2 things, or quit the SUM of the SQL or quit the $db->GetNumRows.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.