MySQL data
#1

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
Reply
#2

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.
Reply
#3

`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.
Reply
#4

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
Reply
#5

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?
Reply
#6

Anyone help?
Reply
#7

PHP код:
forward OnPlayerDataLoaded(playerid);
 
public 
OnPlayerConnect(playerid)
{
    new 
query[128], pname[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpnameMAX_PLAYER_NAME);
    
mysql_format(MySQLquerysizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e' LIMIT 1"pname);
    
mysql_pquery(MySQLquery"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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)