MySQL data - 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 data (
/showthread.php?tid=659413)
MySQL data -
Electrifying - 02.10.2018
How to store data from a column in a variable? I'm making a command to rename the player and I need to check if his name is the same to others players
Re: MySQL data -
DAKYSKYE - 02.10.2018
I'm not sure what you are literally asking for, but if you ask how to check if some name exists in database's player's table, let's query this
PHP код:
SELECT * FROM Players WHERE Username = '<Player Name>'
Anyways I prefer you to see documentation of samp mysql.
Re: MySQL data -
Calisthenics - 02.10.2018
`SELECT
* FROM table_name` will fetch ANY column. Do not use this unless you want to retrieve everything for a player.
There is `COUNT` aggregate function which returns a 0/1 in your case.
You still execute 2 queries to check and update. All this can be done in 1 query using the keyword `IGNORE` and affected rows. Set the column for username as UNIQUE KEY and then execute your update query:
pawn Код:
UPDATE IGNORE table_name SET ...
after executing the query, check how many rows were affected. If it is 0, this means there is a player with this name and hid the warning (for duplicate) as it was instructed to (by the keyword `IGNORE`). If the affected rows is 1, it updated the new name.
Re: MySQL data -
Electrifying - 02.10.2018
Quote:
Originally Posted by DAKYSKYE
I'm not sure what you are literally asking for, but if you ask how to check if some name exists in database's player's table, let's query this
PHP код:
SELECT * FROM Players WHERE Username = '<Player Name>'
Anyways I prefer you to see documentation of samp mysql.
|
I'm making a command to change the name of the player using SetPlayerName, but first I need to see if his name is not the same as the others
Re: MySQL data -
Electrifying - 02.10.2018
Quote:
Originally Posted by Calisthenics
`SELECT * FROM table_name` will fetch ANY column. Do not use this unless you want to retrieve everything for a player.
There is `COUNT` aggregate function which returns a 0/1 in your case.
You still execute 2 queries to check and update. All this can be done in 1 query using the keyword `IGNORE` and affected rows. Set the column for username as UNIQUE KEY and then execute your update query:
pawn Код:
UPDATE IGNORE table_name SET ...
after executing the query, check how many rows were affected. If it is 0, this means there is a player with this name and hid the warning (for duplicate) as it was instructed to (by the keyword `IGNORE`). If the affected rows is 1, it updated the new name.
|
Thanks, and how do I send a message to the player warning that it did not work?
Re: MySQL data -
Electrifying - 02.10.2018
Anyone help?
Re: MySQL data -
NativeZ - 03.10.2018
PHP код:
forward OnPlayerDataLoaded(playerid);
public OnPlayerConnect(playerid)
{
new query[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, MAX_PLAYER_NAME);
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e' LIMIT 1", pname);
mysql_pquery(MySQL, query, "OnPlayerDataLoaded", "d", playerid);
return 1;
}
public OnPlayerDataLoaded(playerid)
{
//Query processed, you can now execute cache functions (like cache_get_row) here.
new NumRows = cache_num_rows();
printf("There are %d players with the same name.", NumRows);
return 1;
}
Found this for you in the docs
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_pquery