Generating Different Information on Each Line of the Dialog
#1

I am trying to generate different information of different locations and IDs in the dialog.
Without any success.

I bassicly want it to check how many rows has been found in the database and create an equivalent amount of 'list-items' inside that dialog.

I have tried it with a while loop and a for loop but my code just simply won't work correctly, it'll only post the last row that has been found in the database.
The code will bassicly run through everything in the database, select the last row, and put one 'list-item' inside the dialog instead of doing it for every row.

Code:

pawn Код:
YCMD:viewdealerships(playerid, params[], help) {

    if(!IsPlayerAdmin(playerid)) return 0;
    else {
        mysql_tquery(dbHandle, "SELECT * FROM `dealerships`", "viewDEALERSHIPS", "d", playerid);
    }
    return 1;
}

forward viewDEALERSHIPS(playerid);
public viewDEALERSHIPS(playerid) {
    new string[1000];
    new i = 0;
    new rows = cache_get_row_count(dbHandle);
    while(i < rows) {
        format(string, sizeof(string), "[ID:%d] [PosX:%f] [PosY:%f] [PosZ:%f]\n", rows, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ]);
        i++;
    }
    ShowPlayerDialog(playerid, DIALOG_VIEW_DEALERSHIPS, DIALOG_STYLE_LIST, "All of DEALERSHIPss INFORMATION", string, "Close", "");
    return 1;
}
Reply
#2

You're running a query to list the number of rows and display the data but why a query if you just want to get the number of rows? If I'm not wrong, you're forgetting to assign the array values equal to the data obtained from the database.

Also, instead of using 'rows' for noting the ID on format, use 'i'. 'rows' will output only the number of rows.
Reply
#3

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
You're running a query to list the number of rows and display the data but why a query if you just want to get the number of rows? If I'm not wrong, you're forgetting to assign the array values equal to the data obtained from the database.

Also, instead of using 'rows' for noting the ID on format, use 'i'. 'rows' will output only the number of rows.
Mhm-.. I didn't quite understand that. Could you give me an example(Or another explanation)?
Reply
#4

You're overwriting "string" all the time, so it'll only display the last one. Change this:
pawn Код:
format(string, sizeof(string), "[ID:%d] [PosX:%f] [PosY:%f] [PosZ:%f]\n", rows, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ]);
into this:
pawn Код:
format(string, sizeof(string), "%s[ID:%d] [PosX:%f] [PosY:%f] [PosZ:%f]\n", string, i, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ]);
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
You're overwriting "string" all the time, so it'll only display the last one. Change this:
pawn Код:
format(string, sizeof(string), "[ID:%d] [PosX:%f] [PosY:%f] [PosZ:%f]\n", rows, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ]);
into this:
pawn Код:
format(string, sizeof(string), "%s[ID:%d] [PosX:%f] [PosY:%f] [PosZ:%f]\n", string, i, DS[i][DsLocX], DS[i][DsLocY], DS[i][DsLocZ]);
Oh, okay, now that I find easier to understand.
This'll solve my issue? There's no need to change any other part of the code, right?


Btw:

I changed 1000 cells in the string variable to 300 and that caused some of the code not to appear, is there any way I can get the amount of required cells and just put them inside the string?
Because if I do not do that then the information would stop if I don't have enough cells.

Is it possible to do something like that?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)