Hi. I am editing inside a plugin and am struggling on polishing the final bits which is to print a fetched result string from a query onto a single line. Everything works as intended, when having PrintToChat() inside the while loop, it does print all the results.. but in multiple message lines, making it appear as spam. I want to format it in to an easier read, to one single line with commas between each previous nickname. That's what I want to accomplish. I'm relatively new to SQL.
If I put the printtochat function outside the while loop, it's only going to print 1 result / row.
Code:
public OnPluginStart() {
.......
.......
RegConsoleCmd("sm_nick", CommandPreviousNickname);
}
..................
public Action CommandPreviousNickname(client, args)
{
if(args > 0)
{
ReplyToCommand(client, "Usage: sm_nick / !nick");
return Plugin_Handled;
}
if(!client)
{
return Plugin_Handled;
}
decl String:buffer[512];
decl String:sAuth[64];
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
Format(buffer, sizeof(buffer), "SELECT DISTINCT name from player_analytics where auth = '%s'", sAuth);
SQL_TQuery(g_DB, SQL_PreviousNickCallback, buffer, client);
return Plugin_Handled;
}
public SQL_PreviousNickCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl == INVALID_HANDLE)
{
ThrowError("PreviousNick callback SQL error: %s", error);
return;
}
if(!IsClientInGame(data))
{
return;
}
decl String:nicks[50];
while(SQL_FetchRow(hndl))
{
SQL_FetchString(hndl, 0, nicks, sizeof(nicks));
PrintToChat(data, "This player has played as: %s", nicks);
}
Thanks in advance