a_bertrand wrote:SELECT SUM(user_coins) AS TOTAL FROM users
That didn't show anything when I made the changes. I have the below code, but only shows the first person in the database, and doesn't count the numbers in the row itself. If that made sense lol... Thanks
$sql = "SELECT *, SUM(user_coins) FROM users having count(*) > 0 ";
$user_query = mysql_query($sql);
$numrows = mysql_num_rows($user_query);
while ($row = mysql_fetch_array($user_query)) {
echo $row['SUM(user_coins)'];
}
Thx!!!
Hello,
I suspect your query is not working as intended? Just out of curiousity, can you give a few example rows from users and write a few rows what you are expecting.
If you to retrieve data with a SUM(), you should add a group by in the end, something to give the query to know how to sum the rows.
so, SELECT user_id, sum(user_coins) from users group by user_id would show:
1 - 400
2 - 300
..etc..
which is probably what you want? In order for this to work, you need to have several rows in users table with user_id.
Or do you want,
1 - TOTAL SUM OF COINS (all players combined)
2 - TOTAL SUM OF COINS (all players combined) (same amount as 1)
?
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
It sums of the amount of coins that are in the row for user_coins just perfect. So it would add 1 + 10 + 2 and give me 13 coins as total. The code I have is working fine.
MikuzA wrote:Hello, not sure why it works but it should be what a_bertrand said if you only wish for SUM of the user_coins.
a_bertrand wrote:SELECT SUM(user_coins) AS TOTAL FROM users
The problem is where I take the *, out of the Select, it shows nothing. And if I remove the count * from it, it shows nothing. The only way I could get it to count the total coins was to write it like I did.
$sql = "SELECT *, SUM(user_coins) FROM users having count(*) > 0 ";