Looping
#1

How would i go about showing all rows in a Mysql database in a dialog.
Reply
#2

pawn Code:
CMD:results(playerid,params[])
{
    mysql_query("SELECT * FROM `table`");
    mysql_store_resul();
    if(mysql_num_rows())
    {
        new msg[512];
        while(mysql_retrieve_row())
        {
            new tmp[24],name[24],Float:health,id;
            mysql_fetch_field_row(name,"name");
            mysql_fetch_field_row(tmp,"health"); health = floatstr(tmp);
            mysql_fetch_field_row(tmp,"id"); id = strval(tmp);
            format(msg,sizeof(msg),"%s%s - %d - %02f\n",msg,name,id,health);
        }
        ShowPlayerDialog(playerid,0,DIALOG_STYLE_LIST,"SQL Results",msg,"Close","");
    }
    else ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,"SQL Results","No results found","Close","");
    return 1;
}
Reply
#3

Quote:
Originally Posted by ihatetn931
View Post
How would i go about showing all rows in a Mysql database in a dialog.
1. Loop through the Data...look how you do this in your mysql version

2. declare a string, add the lines from the database with strcat to the string

3. You can show you the dialog under the loop with the string you've declared.

Greekz
Reply
#4

Use R33 mysql plugin

I've tried to put my row count i get from my Loadfunction in a variable

so
pawn Code:
cache_get_data(rows, fields, dbHandle);

BuildingRows = rows;
Which gives me in a print, which is correct since there is 3 rows.
Code:
Building 1
Building 2
Building 3
That prints when i type this command

pawn Code:
YCMD:test(playerid, params[], help)
{
    #pragma unused params
    new str[128];
    if(PLogged[playerid] == 0) return
        SendClientMessage(playerid, ERROR_COLOR, NOT_LOGGED);
    if(PlayerInfo[playerid][pAdmin] < 9 && !IsPlayerAdmin(playerid)) return
        SendClientMessage(playerid, COLOR_GREY, ADMIN_CMD_ERROR);
    if (help) return
        SendClientMessage(playerid, COMMAND_HELP_COLOR, "Test command");
    for (new i = 0; i < BuildingRows; i++)
    {
        printf("Building Rows %d", i+1);
        format(str, sizeof(str), "%d %s\n", BuildingInfo[i][buMysqlId],BuildingInfo[i][buName]);
        ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"Test",str,"Select","");
    }
    return 1;
}
I can get it to show 1 row but not all of them at once

I've never used that strcat function.

I don't wanna have to fetch the data that has already been fetched with my loadfunction
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)