SA-MP Forums Archive
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: MySQL (/showthread.php?tid=470585)



MySQL - Wizzy951 - 18.10.2013

Hello everybody! I consider making a system which counts the player accounts (from mysql database) and I wonder how can I get the last registered player ID ?

Notes:
I'm using BlueG R34 mysql plugin and also ID is Auto Increment (it stays for account ID).
Well, the idea is just to show to the new players how much players are registered.

Thanks in advance


Respuesta: MySQL - PabloDiCostanzo - 18.10.2013

If youґd already the mysql created, you should just go to the php and look the last user registred and you will check who was...

I donґt know if is this what are you asking for?


Re: Respuesta: MySQL - Wizzy951 - 18.10.2013

Quote:
Originally Posted by PabloDiCostanzo
Посмотреть сообщение
If youґd already the mysql created, you should just go to the php and look the last user registred and you will check who was...

I donґt know if is this what are you asking for?
No, you didn't get what I meant. I'm not going to change my script after a player registers. Let me give you an example: Welcome to the server, we've already 20 registered players you are about to become the 21st. He creates an account with ID 21. New non-registered player joins and it tells him that the server has 21 registered players he will be the 22nd and etc. (i.e. when the 22nd joins it gets that the last one is 21nd).


Re: MySQL - Jefff - 19.10.2013

pawn Код:
SELECT column_name FROM table_name ORDER BY column_name DESC LIMIT 1;
or just use

pawn Код:
SELECT COUNT(`id`) FROM table_name;



Re: MySQL - Wizzy951 - 19.10.2013

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
SELECT column_name FROM table_name ORDER BY column_name DESC LIMIT 1;
or just use

pawn Код:
SELECT COUNT(`id`) FROM table_name;
I'm kinda confused now, if it should become:
pawn Код:
new
       string[64],
       query[64];
format (query, sizeof(query), "SELECT COUNT(`id`) FROM table_name;");
mysql_function_query(Database, query, false, "", "");

format(string, sizeof(string), "We already have %i registered players.", /*variable*/);
ShowPlayerDialog(playerid, DIALOGID, 0, "Welcome", string, "OK", "");
But which is the placeholder with the result of the sent query ? What should be the commented variable should it actually be the "query"?


Re: MySQL - Misiur - 19.10.2013

You don't have to use format, because you aren't inserting any value there. Also you have to cache the result:

pawn Код:
mysql_tquery(Database, "SELECT COUNT(`id`) FROM table_name", "SQLGetCount", "i", playerid);

//then later
forward SQLGetCount(playerid);
public SQLGetCount(playerid) {
    new
        string[64];

    //We always get exactly one row, no need to use cache_get_data
    format(string, sizeof(string), "We already have %i registered players.", cache_get_row_int(0, 0, Database));
    ShowPlayerDialog(playerid, DIALOGID, 0, "Welcome", string, "OK", "");

    return 1;
}



Re: MySQL - Wizzy951 - 19.10.2013

Quote:
Originally Posted by Misiur
Посмотреть сообщение
You don't have to use format, because you aren't inserting any value there. Also you have to cache the result:

pawn Код:
mysql_tquery(Database, "SELECT COUNT(`id`) FROM table_name", "SQLGetCount", "i", playerid);

//then later
forward SQLGetCount(playerid);
public SQLGetCount(playerid) {
    new
        string[64];

    //We always get exactly one row, no need to use cache_get_data
    format(string, sizeof(string), "We already have %i registered players.", cache_get_row_int(0, 0, Database));
    ShowPlayerDialog(playerid, DIALOGID, 0, "Welcome", string, "OK", "");

    return 1;
}
Thank you, REP+!