MySQL get Name - 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 get Name (
/showthread.php?tid=613099)
MySQL get Name -
Ahmed21 - 24.07.2016
Hello everyone, so I've thought hard how to make a function to: Enter an account ID and it returns the account name. My MySQL "accounts" table got: "ID" (account ID), "Name" (account name) bla bla bla
So, can someone make me a function to enter an account ID and it returns the account name? for Example:
/getaccname [ACCOUNT_ID], it searches if this account ID exists, if ye, it returns a name..
Please.
Re: MySQL get Name -
Flake. - 24.07.2016
PHP код:
GetNameFromSQL_ID(sqlid)
{
new query[128], name[64];
mysql_format(SQL_CONNECTION, query, sizeof(query), "SELECT Name FROM `Your_Table` WHERE ID = %d LIMIT 1", sqlid);
new Cache:result = mysql_query(SQL_CONNECTION, query);
cache_get_field_content(0, "Name", name, SQL_CONNECTION, 64); //or what ever your players name saves as
cache_delete(result);
return name;
}
Something like that should work.
Re: MySQL get Name -
Ahmed21 - 24.07.2016
Quote:
Originally Posted by Flake.
PHP код:
GetNameFromSQL_ID(sqlid)
{
new query[128], name[64];
mysql_format(SQL_CONNECTION, query, sizeof(query), "SELECT Name FROM `Your_Table` WHERE ID = %d LIMIT 1", sqlid);
new Cache:result = mysql_query(SQL_CONNECTION, query);
cache_get_field_content(0, "Name", name, SQL_CONNECTION, 64); //or what ever your players name saves as
cache_delete(result);
return name;
}
Something like that should work.
|
Thank you so much. +REP'd
Re: MySQL get Name -
Konstantinos - 24.07.2016
Don't forget to check if there are rows (cache_get_row_count function) before calling cache_get_field_content otherwise you'll get a warning for invalid row.