SA-MP Forums Archive
Tiny SQL error I can't find? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Tiny SQL error I can't find? (/showthread.php?tid=614098)



Tiny SQL error I can't find? - JaydenJason - 04.08.2016

So I'm working on this dynamic faction system and I'm trying to list all factions, some weird reason it just lists the first column times the count of factions. I've tried debugging but I honestly can't see what I've done wrong?

Код:
mysql_tquery(mysql, "SELECT `fName` FROM `factions` ORDER BY `fID` ASC", "ListFactions", "i", playerid);
Код:
forward ListFactions(playerid);
public ListFactions(playerid)
{
    new count = 0, rows, fields;
    cache_get_data(rows, fields, mysql);
    printf("start of list");
    if(rows)
    {
    	printf("if rows:%i", rows);
	    new facname[MAX_FACTIONS][50], faclist[300];
	    while(count < rows)
	    {
	    	cache_get_field_content(0, "fName", facname[count], mysql, 255);
	    	format(faclist, sizeof(faclist), "%s%s\n", faclist, facname[count]);
	    	printf("facname:%s count:%i rows:%i", facname[count], count, rows);
	    	count++;
	    }
	    return ShowPlayerDialog(playerid, DIALOG_FACTION_LIST, DIALOG_STYLE_LIST, "List Factions", faclist, "Okay", "");
    } 
    else 
    {
    	SendErrorMessage(playerid, "There are no factions.");
    	return cmd_factions(playerid, "");
    }
}
Код:
[11:35:22] start of list
[11:35:22] if rows:3
[11:35:22] facname:Los Santos Police Department count:0 rows:3
[11:35:22] facname:Los Santos Police Department count:1 rows:3
[11:35:22] facname:Los Santos Police Department count:2 rows:3



(Don't comment on the variable sizes, those still need to be changed)


Re: Tiny SQL error I can't find? - Vince - 04.08.2016

If you know the number of iterations you should use a for-loop. But your actual problem is that you're always accessing row 0.
Код:
cache_get_field_content(0, ...



Re: Tiny SQL error I can't find? - JaydenJason - 04.08.2016

Quote:
Originally Posted by Vince
Посмотреть сообщение
If you know the number of iterations you should use a for-loop. But your actual problem is that you're always accessing row 0.
Код:
cache_get_field_content(0, ...
I don't know what it was with me but I knew 100% you'd respond to my thread lol, thanks for the assistance. I'm going to change everything about it very soon, this was just a quick test phase.