27.02.2014, 06:32
How to get a total amount of Players with mySQL I want it to say how many Registered players the server got by typing:
CMDlayers
The table I use is: Accounts
CMDlayers
The table I use is: Accounts
CMD:players(playerid, params[])
SELECT ID FROM Accounts
new NumPlayers = mysql_num_rows();
printf("Registered players: %i", NumPlayers);
// This command "/registeredplayers" displays the amount of registered players
COMMAND:registeredplayers(playerid, params[])
{
// Setup local variables
new NumPlayers, Msg[128];
// Execute the query to get all ID's from all accounts in table "Accounts"
mysql_query("SELECT ID FROM Accounts");
// Store the result
mysql_store_result();
// Count the amount of rows returned in the result
NumPlayers = mysql_num_rows();
// Free the result
mysql_free_result();
format(Msg, sizeof(Msg), "Registered players: %i", NumPlayers);
SendClientMessage(playerid, -1, Msg);
// Let the server know that this was a valid command
return 1;
}
CMD:registeredplayers(playerid, params[])
{
inline FetchResults() {
//Result is always present
new
numberOfPlayers = cache_get_row_int(0, 0, dbhandle)
;
//Do something with numberOfPlayers
}
mysql_pquery_inline(dbhandle, "SELECT COUNT(id) FROM Accounts", using inline FetchResults);
return 1;
}