MySQL Registered Players! - 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: MySQL Registered Players! (
/showthread.php?tid=497498)
MySQL Registered Players! -
Mriss - 27.02.2014
How to get a total amount of Players with mySQL I want it to say how many Registered players the server got by typing:
CMD
layers
The table I use is: Accounts
Re: MySQL Registered Players! -
Mriss - 27.02.2014
pawn Код:
CMD:players(playerid, params[])
Re: MySQL Registered Players! -
PowerPC603 - 27.02.2014
Query:
Code:
pawn Код:
new NumPlayers = mysql_num_rows();
printf("Registered players: %i", NumPlayers);
Re: MySQL Registered Players! -
Mriss - 27.02.2014
Could you do the full cmd?
Re: MySQL Registered Players! -
PowerPC603 - 27.02.2014
pawn Код:
// 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;
}
Something like this should work.
Re: MySQL Registered Players! -
Vince - 27.02.2014
The proper way to do this is actually the
COUNT() function, not mysql_num_rows.
Re : MySQL Registered Players! -
anou1 - 27.02.2014
Hi,
Is there a way to count total registred players with threaded queries? Or should I use this ?
If I want to use this but for a textdraw, will it be the same ?
Thank you.
Re: MySQL Registered Players! -
Misiur - 27.02.2014
Threaded queries need callback. You can use y_inline to keep it inside one function:
pawn Код:
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;
}