Problem with format
#1

Hey,
I have this code:
Код:
ocmd:leader(playerid)
{
	if(player[playerid][pAdmin] <= 3)return SendErrorMessage(playerid);
	new string[500], i = 0;
	new rows = mysql_tquery(1,"SELECT * FROM `fraktionen`","OnFraksCount");
	for(;i < rows; i++)
	{
		format(string,sizeof(string)," %s%s | "#HEXBlue"%s\n",string, fraktion[i][f_name], fraktion[i][f_leader]);
	}
	printf("%s",string);
	ShowPlayerDialog(playerid,DIALOG_ADM_FRAK, DIALOG_STYLE_LIST," Fraktionen", string,"Weiter", "Abbrechen");
 	return 1;

}
The problem is that there is only one fraktion in the string. That means, the string is "LSPD | Playername".
But I have 3 fraks in my DB, so why is there just one in the string?
"Rows" has the value 3 - that is right.
Reply
#2

I think it's because all data is being sent to your callback, so you should have
Quote:

for(;i < rows; i++)
{
format(string,sizeof(string)," %s%s | "#HEXBlue"%s\n",string, fraktion[i][f_name], fraktion[i][f_leader]);
}
printf("%s",string);
ShowPlayerDialog(playerid,DIALOG_ADM_FRAK, DIALOG_STYLE_LIST," Fraktionen", string,"Weiter", "Abbrechen");
return 1;

in your callback instead ? ("OnFraksCount")
To get the amount of rows in your callback, use...
Quote:

cache_get_data(rows, fields, dbHandle);

this should get all the data from the db... (dbHandle is my handle, which yours seems to be 1? always best to keep the DB handle as a variable instead, incase it isn't 1 for some weird reason).
Quote:

if(rows) {
}

this will make sure rows is larger than 0, so you can use an else statement to alert you if no data is getting retrieved

Im not the best pawn scripter but i'm just saying from my past experience I use blueG's mysql plugin, so it may be different depending on what plugin you use.
Reply
#3

I actually fixed it this way:
- Global var
- Count the rows in the DB while loading
- var = rows
- replace the query with the var
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)