Raised This Month: $51 Target: $400
 12% 

Solved SQL storing multiple result rows


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deville
AlliedModders Donor
Join Date: Oct 2016
Old 03-05-2018 , 16:05   SQL storing multiple result rows
Reply With Quote #1

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

Last edited by deville; 03-05-2018 at 16:57.
deville is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-05-2018 , 16:41   Re: SQL storing multiple result rows
Reply With Quote #2

You need to create an output buffer string so you can set all your text and then print it when your done.
__________________
Neuro Toxin is offline
Reiko1231
Member
Join Date: Apr 2013
Location: Russia
Old 03-05-2018 , 16:41   Re: SQL storing multiple result rows
Reply With Quote #3

Use Format function to concatenate all nicknames

Last edited by Reiko1231; 03-05-2018 at 16:42.
Reiko1231 is offline
deville
AlliedModders Donor
Join Date: Oct 2016
Old 03-05-2018 , 16:56   Re: SQL storing multiple result rows
Reply With Quote #4

Thanks guys! Managed to receive same help from Chaosxk just recently. All sorted!
deville is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode