Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Need help with MySQL!  (Read 1011 times)

0 Members and 1 Guest are viewing this topic.
Need help with MySQL!
« on: September 13, 2007, 05:47:23 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 178
I have a column (money) in a table (users) and there's many rows in the table, and I'd like to sum up all the columns named 'money', but I don't know how to do it. Basically, I want it to sum up all money from all users on my website, since I'm making an info page for how many members there are, how much money all of 'em have together, you get it.

Code: [Select]
$usercount=mysql_num_rows(mysql_query("SELECT * FROM users"));
echo "Total Amount of Members: <b>" . $usercount . "</b><br>";

I found out how to do that, but how to do money? I bet I know, just, I forgot how. So please, help?
Logged

Dayjo

shut the fuck up donny.
Re: Need help with MySQL!
« Reply #1 on: September 13, 2007, 06:10:54 pm »
  • hungry..
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3602
Code: [Select]
$sql = "SELECT * FROM `users`";
$result = mysql_query($sql);

if($result){

    $userCount = mysql_num_rows($result);
    echo "Total Amount of Members: <b>" . $usercount . "</b><br /><br />";
   
    while($row = mysql_fetch_array($result)){
         echo $row['username'] . ": " . $row['money'] . "<br />";
    }
}

or something?
Logged
  • My Blog
Re: Need help with MySQL!
« Reply #2 on: September 13, 2007, 06:18:50 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 178
Well, your code worked (hehe), but it didn't work as I wanted it to. Maybe I wasn't explaining good but I'll try again. XD

I have a table, for example:

id -- username -- money
1 -- Frebby -- 1066
2 -- Arnold -- 156999
3 -- Gates -- 151988456

So I want to sum up the column "money" into one big number. Somehow make all the numbers in the column "money" to add themselves up, and in this case the result would become $152,146,521 (1066 + 156999 + 151988456)

Dayjo, what your code did was list all usernames and their money sepereratly. But I appreciate your help!
Logged

mit

Re: Need help with MySQL!
« Reply #3 on: September 13, 2007, 06:44:26 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Code: [Select]
$sql = "SELECT * FROM `users`";
$result = mysql_query($sql);

$total=0;
if($result){
    while($row = mysql_fetch_array($result)){
         $total+= $row['money'];
    }
echo "Total money:".$total;
}
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Need help with MySQL!
« Reply #4 on: September 13, 2007, 06:57:31 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 178
Thanks mit, that worked great! I appreciate both of your help, and sorry for any troubles. ^^
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.32 seconds with 45 queries.

anything