View Single Post
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 05-21-2019 , 12:30   Re: MYSQL - How To Select a row and print it out
Reply With Quote #2

PHP Code:
public void SomeFunction(int Client)
{
    if(!
IsClientInGame(Client)) return;

    
char sQuery[1024], userName[64];
    
GetClientName(ClientuserNamesizeof(userName));
    
g_Database.Escape(userNameuserNamesizeof(userName));

    
Format(sQuerysizeof(sQuery), "SELECT * FROM test WHERE name='%s';"userName);
    
g_Database.Query(SQL_SelectTestsQueryGetClientUserId(Client));
}

public 
void SQL_SelectTest(Database dbDBResultSet results, const char[] sErrorany data)
{
    if(
results == null)
    {
        
LogError("MySQL Query Failed: %s"sError);
        return;
    }

    if(!
results.FetchRow()) return;

    
int Client GetClientOfUserId(data);
    if(!
IsClientInGame(Client)) return;

    
int pointsCol;
    
results.FieldNameToNum("points"pointsCol);
    
int points results.FetchInt(idCol);
    
PrintToChat(Client"You have %i Points."points);

Obviously you need a valid database connection before doing any of this which you can see how to do here: https://wiki.alliedmods.net/SQL_(Sou...)#Connecting_2
CliptonHeist is offline