02.10.2018, 17:50
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
SELECT * FROM Players WHERE Username = '<Player Name>'
UPDATE IGNORE table_name SET ...
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 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 Код:
|
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;
}