Add all columns in MySQL? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Add all columns in MySQL? (
/showthread.php?tid=549693)
Add all columns in MySQL? -
Derexi - 08.12.2014
I want to work out how many hours all the players have been connected for all together by adding all the hours from the database... how could I do this?
Re: Add all columns in MySQL? -
welderlourenco - 08.12.2014
Hello Derexi,
You could create a column named
connected_time (integer) (default to 0) inside your players table and save the data in seconds,
OnPlayerConnect you get the current time and set it to your players variable,
OnPlayerDisconnect you get the current time again and use to get the difference between the connect time and the current time, casting it to seconds, at the end just make sure to increment the value in the database when you save the player progress.
After that you could easyly create a command to show the time each player has been connected,
Hope it help you.
Re: Add all columns in MySQL? -
Derexi - 08.12.2014
Quote:
Originally Posted by welderlourenco
Hello Derexi,
You could create a column named connected_time (integer) (default to 0) inside your players table and save the data in seconds,
OnPlayerConnect you get the current time and set it to your players variable,
OnPlayerDisconnect you get the current time again and use to get the difference between the connect time and the current time, casting it to seconds, at the end just make sure to increment the value in the database when you save the player progress.
After that you could easily create a command to show the time each player has been connected,
Hope it help you.
|
I appreciate your help, but this isn't what I'm looking for. I've already made a system that counts and saves players' online time in seconds. I now want to add up each player's seconds together to get the total amount of seconds that all the players, collectively, have played in the server. Like this:
Table in MySQL database:
Код:
ID | Name | Online_seconds
1 Bob 3600 + <----- I need a code to add all these seconds
2 Tom 3240 +
3 Sam 2100 = 8940 <----- to get this number
Re: Add all columns in MySQL? -
Lordzy - 08.12.2014
You can use
SUM function to retrieve the sum of mentioned field from all rows.
Код:
SELECT SUM(field_name) FROM table_name
Re: Add all columns in MySQL? -
welderlourenco - 08.12.2014
Quote:
Originally Posted by Derexi
I appreciate your help, but this isn't what I'm looking for. I've already made a system that counts and saves players' online time in seconds. I now want to add up each player's seconds together to get the total amount of seconds that all the players, collectively, have played in the server. Like this:
Table in MySQL database:
Код:
ID | Name | Online_seconds
1 Bob 3600 + <----- I need a code to add all these seconds
2 Tom 3240 +
3 Sam 2100 = 8940 <----- to get this number
|
In that case you can do exactly what
Lordzy said,
You can retrieve the total of seconds right from the database:
Код:
select sum(`Online_seconds`) from `your_table`;