MySQL get Name
#1

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

PHP код:
GetNameFromSQL_ID(sqlid)
{
    new 
query[128], name[64];
    
mysql_format(SQL_CONNECTIONquerysizeof(query), "SELECT Name FROM `Your_Table` WHERE ID = %d LIMIT 1"sqlid);
    new 
Cache:result mysql_query(SQL_CONNECTIONquery);
    
cache_get_field_content(0"Name"nameSQL_CONNECTION64);  //or what ever your players name saves as
     
cache_delete(result);
    return 
name;

Something like that should work.
Reply
#3

Quote:
Originally Posted by Flake.
Посмотреть сообщение
PHP код:
GetNameFromSQL_ID(sqlid)
{
    new 
query[128], name[64];
    
mysql_format(SQL_CONNECTIONquerysizeof(query), "SELECT Name FROM `Your_Table` WHERE ID = %d LIMIT 1"sqlid);
    new 
Cache:result mysql_query(SQL_CONNECTIONquery);
    
cache_get_field_content(0"Name"nameSQL_CONNECTION64);  //or what ever your players name saves as
     
cache_delete(result);
    return 
name;

Something like that should work.
Thank you so much. +REP'd
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)