Loop with SQLite - 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: Loop with SQLite (
/showthread.php?tid=291515)
Loop with SQLite -
Cowboy - 20.10.2011
Hello
I tried to do the following but it didn't work
pawn Код:
command(gangs, playerid, params[])
{
new tGid[5], tGname[100], tGOwner[25], Query[200], string[1000], DBResult:Result;
format(Query, sizeof(Query), "SELECT * FROM `GANGS` DESC limit 10");
Result = db_query(Database, Query);
for (new i; i < db_num_rows(Result); i++)
{
db_get_field(Result, 0, tGname, sizeof(tGname));
db_get_field(Result, 1, tGid, 5);
db_get_field(Result, 2, tGOwner, sizeof(tGOwner));
// db_get_field_assoc(Result, "NAME", tGname, sizeof(tGname));
// db_get_field_assoc(Result, "OWNER", tGOwner, sizeof(tGOwner));
// db_get_field_assoc(Result, "ID", tGid, 5);
format(string, sizeof(string), "ID: %d Name: %s Owner: %s\r\n", strval(tGid), tGname, tGOwner);
ShowPlayerDialog(playerid, DIALOG_GANG_INFO, DIALOG_STYLE_LIST, "Gang War", string, "Info", "Cancel");
db_next_row(Result);
}
if(db_num_rows(Result) == 0) return ShowPlayerDialog(playerid, DIALOG_GANG_INFO, DIALOG_STYLE_LIST, "Gang War", "No gangs", "Info", "Cancel");
return 1;
}
The commented part didn't work either. How to make it so it will list all gangs made?
Re: Loop with SQLite -
=WoR=Varth - 20.10.2011
pawn Код:
command(gangs, playerid, params[])
{
new tGid[5], tGname[100], tGOwner[25], Query[200], string[1000], DBResult:Result;
format(Query, sizeof(Query), "SELECT * FROM `GANGS` DESC limit 10");
Result = db_query(Database, Query);
for (new i; i < db_num_rows(Result); i++)
{
db_get_field(Result, 0, tGname, sizeof(tGname));
db_get_field(Result, 1, tGid, 5);
db_get_field(Result, 2, tGOwner, sizeof(tGOwner));
// db_get_field_assoc(Result, "NAME", tGname, sizeof(tGname));
// db_get_field_assoc(Result, "OWNER", tGOwner, sizeof(tGOwner));
// db_get_field_assoc(Result, "ID", tGid, 5);
format(string, sizeof(string), "%sID: %d Name: %s Owner: %s\r\n",string,strval(tGid), tGname, tGOwner);
db_next_row(Result);
}
ShowPlayerDialog(playerid, DIALOG_GANG_INFO, DIALOG_STYLE_LIST, "Gang War", string, "Info", "Cancel");
if(db_num_rows(Result) == 0) return ShowPlayerDialog(playerid, DIALOG_GANG_INFO, DIALOG_STYLE_LIST, "Gang War", "No gangs", "Info", "Cancel");
return 1;
}
Re: Loop with SQLite -
Cowboy - 20.10.2011
It works, thank you. Rep
I have a question. This I have included in the select statement: DESC limit 10
Will it show the first 10 gangs? I'd like it to show unlimited
Re: Loop with SQLite -
=WoR=Varth - 20.10.2011
Remove it then.
Re: Loop with SQLite -
Cowboy - 20.10.2011
Thank you.