Need Help with Mysql.
#1

I'm working on a command which shows the last text someone typed in that chat.
Everything works fine, the text is getting stored in the database. But the only problem is
that whenever I use that command, only the first record is shown. For example.
I type "Hey" in chat. It gets saved into the database with the ID 0 (auto-increment).
Now if I type "Bye" in chat, it gets saved into the database with the ID 1.
Whenever I use the command /last chat "playerid" it only displays "Bye" instead of "Bye" and "Hey".
This is my command.

Код:
CMD:last(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] > 0)
	{
		new item[256], otherid, othername[MAX_PLAYER_NAME];
		GetPlayerName(otherid, othername, sizeof(othername));
		if(sscanf(params, "s[256]r", item, otherid)) 
		{
			SendClientMessage(playerid, COLOR_GREY, "Usage: {FFFFFF}/last [action] [playerid]");
			SendClientMessage(playerid, COLOR_GREY, "Last: Chat");
		}
		else if(strcmp(item, "chat", true) == 0)
		{
			new query[512];
			mysql_format(mysql, query, sizeof(query), "SELECT * FROM `chatlog` WHERE `chatName` = '%s' LIMIT 10", othername);
			new Cache: salkf = mysql_query(mysql, query);
			new test2[512], test3[512], csf[512];
			for(new i, j = cache_get_row_count(); i != j; ++i)
			{
				cache_get_field_content(i, "chatString", test2); 
				cache_get_field_content(i, "chatTime", test3);
				format(csf, sizeof(csf), "[%s] %s.\n", test3, test2);
				ShowPlayerDialog(playerid, DIALOG_LCHAT, DIALOG_STYLE_MSGBOX, "SERVER: Last Chat", csf, "Close", "");
			}
			cache_delete(salkf);
		}
	}
	else return SendClientMessage(playerid, -1, NotAdmin);
	return 1;
}
What did I do wrong?
Reply
#2

Код:
ShowPlayerDialog(playerid, DIALOG_LCHAT, DIALOG_STYLE_MSGBOX, "SERVER: Last Chat", csf, "Close", "");
That should be outside of the loop, else it'll only show the first dialog at the start of the loop, and ShowPlayerDialog does not close the dialog which is already open unless the dialogid is -1 so:

Код:
for(new i, j = cache_get_row_count(); i != j; ++i)
{
	cache_get_field_content(i, "chatString", test2); 
        cache_get_field_content(i, "chatTime", test3);
	format(csf, sizeof(csf), "[%s] %s.\n", test3, test2);
				
}
ShowPlayerDialog(playerid, DIALOG_LCHAT, DIALOG_STYLE_MSGBOX, "SERVER: Last Chat", csf, "Close", "");
That obviously is if 'DIALOG_LCHAT' is not -1, which according to the wiki:

"Using -1 as dialogid closes all dialogs currently shown on the client's screen."

EDIT: Hopefully, you don't use [512] as your final string, since you can only have 128 characters per message, so that'd be ridiculous for the test2, test3 vars.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)