Dialog list with MySQL data.
#1

I want to show some infos from my db using a dialog box. The problem when I use this code is that it show only the last result. I don't know how to make a list of what i want.

Код HTML:
CMD:showrecord(playerid,params[])
	{
		
		new query[128];
		new name[MAX_PLAYER_NAME];
		new result;
		new criminal_charge[128],time,date[128];
		new rows;
		new resultline[200];
		new string[128],string1[128];
		new ID;
			if(sscanf(params, "u", ID)) // We are using sscanf so we define the command format usage
			{
	   			 SendClientMessage(playerid,-1,"USAGE: /showrecord (Player Name/ID)");
	    			return 1;
			}
		GetPlayerName(ID,name,sizeof(name));
			mysql_format(this,query,sizeof(query),"SELECT idx FROM criminal_record WHERE player_name = '%s'",name);
			mysql_query(this,query,true);
			result=cache_get_field_content_int(0,"idx",this);
			format(string,sizeof(string),"ID for this person is %d",result);
			SendClientMessage(playerid,-1,string);
			if(result>0)
			{
				mysql_format(this,query,sizeof(query),"SELECT criminal_charge,time,date FROM criminal_charges WHERE personID='%d'",result);
				mysql_query(this,query,true);
				rows=cache_get_row_count(this);
				format(string,sizeof(string),"Number of rows are : %d ",rows);
				SendClientMessage(playerid,-1,string);
				
			    for(new i=0;i<rows;i++)
				{
				    cache_get_field_content(i,"criminal_charge",criminal_charge,128);
				    time=cache_get_field_content_int(i,"time");
				    cache_get_field_content(i,"date",date,128);
					//sscanf(resultline,"p<|>s[128]ds[128]",criminal_charge, time, date);
					format(string1,sizeof(string1),"%s\t%d\t%s\n",criminal_charge,time,date);
     				SendClientMessage(playerid,-1,string1);

				}
				ShowPlayerDialog(playerid,DIALOG_CRIMINAL_RECORD,DIALOG_STYLE_LIST,"Criminal Records",string1,"Back","");
			}
			else
			{
				SendClientMessage(playerid,COLOR_WHITE,"This person has no criminal record");
			}
		return 1;
	}
That for is working fine but doesn't list the strings in dialog. The dialog shows only the last message, so the last row of my db. Please help me, thank you!
Reply
#2

you have to loop this string1 like this

format(string1,sizeof(string1),"%s\n%s\t%d\t%s",string1,criminal_charge,time,date);
Reply
#3

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)