Loop with SQLite
#1

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?
Reply
#2

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;
}
Reply
#3

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
Reply
#4

Remove it then.
Reply
#5

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)