Dialog List with mysql rows
#1

Hello sa-mp.com,is possible to make a dialog_style_list with case = rows in mysql database?
So example i have an Fine System,and i make a dialog,but i can't show more than 1 fine.Can you help me,please ?

Код:
LoadPlayerFines();
  		format(finelist,sizeof(finelist),"Amenda #%d [{4747D1}$%d{FFFFFF}] pentru '%s'",FinesInfo[playerid][fId],FinesInfo[playerid][fPret],FinesInfo[playerid][fPentru]);
	    ShowPlayerDialog(playerid, 432,DIALOG_STYLE_LIST,"Fines", finelistt, "Detalii", "Close");
LoadPlayerFines();

Код:
if( IsPlayerConnected( playerid ) )
    {
        new DataString[ 1536 ], Query[ 1536 ], sendername[256];
        GetPlayerName(playerid, sendername, sizeof(sendername));
        format( Query, sizeof( Query ), "SELECT * FROM `fines` WHERE `Inssuer` = '%s'", sendername);
        if(mysql_query( Query ))
        {
            mysql_store_result();
        } else {
            mysql_free_result();
            SendClientMessage( playerid, COLOR_WHITE, "MYSQL ERROR LAV, feel free to report this bug by SS'ing it and send it to a dev." );
            printf("Could not call loadaccountvariables query %d %d",playerid,PlayerInfo[playerid][pDatabaseID]);
            Kick(playerid);
        }
        printf(" SQL: %s",Query);
	    for(new fine;fine<MAX_FINES;fine++)
	    {
	        mysql_fetch_field( "ID", DataString );
	        FinesInfo[ playerid ][ fId ] = strval( DataString );

	        mysql_fetch_field( "Price", DataString );
	        FinesInfo[ playerid ][ fPrice ] = strval( DataString );

	        mysql_fetch_field( "For", DataString );
	        strmid(FinesInfo[ playerid ][ fFor ], DataString, 0, strlen(DataString), 255);
		}
        mysql_free_result();
	}
Reply
#2

Your variables can only store 1 row per-player. Add to fId, fPrice and fFor an array with size of MAX_FINES and then with a loop, you'll be able to display them all.
Reply
#3

Код:
GetPlayerName(playerid, sendername, sizeof(sendername));
	    new query[300],query1[300],query2[300],query3[300],query4[300], userstring[300];
		format(query, sizeof(query), "SELECT * FROM fines WHERE Posesor = '%s' ORDER BY ID DESC LIMIT 10", sendername);
		mysql_query(query);
		mysql_store_result();
		while(mysql_num_rows())
		{
		    mysql_fetch_row(query, "ID");
		    mysql_fetch_row(query1, "Inssuer");
		    mysql_fetch_row(query2, "Price");
		    mysql_fetch_row(query3, "For");
		    format(userstring, sizeof(userstring), "Fine #%d [{4747D1}$%d{FFFFFF}] for '%s'", query, query1, query2, query3);
		}
		mysql_free_result();
	    ShowPlayerDialog(playerid, 432,DIALOG_STYLE_LIST,"Fines", userstring, "Details", "Close");
	    return 1;
I try like that,but don't work ;(.I try an additional variante.
mysql: https://sampforum.blast.hk/showthread.php?tid=122983
Reply
#4

You'll have to store the player's name when storing as well, so you can track the ID, you could do it simpler, check for tickets that match the players name.
Reply
#5

Quote:
Originally Posted by Dokins
Посмотреть сообщение
You'll have to store the player's name when storing as well, so you can track the ID, you could do it simpler, check for tickets that match the players name.
With a command?I want this command ("/fines") to show all tickets from this name .If Test_Test have 5 tickets,this dialog need to show 5 tickets.But i don't know how to make this rows in case for dialog.
Reply
#6

If it's fines per-players, then what I meant is this:
pawn Код:
new FinesInfo[MAX_PLAYERS][MAX_FINES][e_FinesInfo /* REPLACE WITH THE NAME OF THE ENUM IS USED TO THE SCRIPT */];
pawn Код:
for(new fine, rows = mysql_num_rows(sql);fine<rows;fine++)
{
    if (fine >= sizeof (FinesInfo)) break;
   
    mysql_fetch_field( "ID", DataString );
    FinesInfo[ playerid ][fine][ fId ] = strval( DataString );
   
    mysql_fetch_field( "Price", DataString );
    FinesInfo[ playerid ][fine][ fPrice ] = strval( DataString );
   
    mysql_fetch_field( "For", DataString );
    strmid(FinesInfo[ playerid ][fine][ fFor ], DataString, 0, strlen(DataString), 255);
}
pawn Код:
// NOTE: finelist should be long enough to store the whole text
for(new fine;fine<MAX_FINES;fine++)
{
    if (!FinesInfo[ playerid ][fine][ fFor ]) break;
   
    format(finelist,sizeof(finelist),"%sAmenda #%d [{4747D1}$%d{FFFFFF}] pentru '%s'",finelist,FinesInfo[playerid][fine][fId],FinesInfo[playerid][fine][fPrice],FinesInfo[playerid][fine][fFor]);
}
ShowPlayerDialog(playerid, 432,DIALOG_STYLE_LIST,"Fines", finelistt, "Detalii", "Close");
I'd suggest you though not to use that outdated plugin and use the one by BlueG, version R39-3 with threaded queries. It is MUCH faster!
Reply
#7

Edit
Reply
#8

Can you help me ?
Reply
#9

At least, does it show the dialog? Try be more specific about what does not work so I can be aware as well.

Since the player can have more fines than 1, you can no longer use them without indexes and listitem is the actual index of it so:
pawn Код:
format(stringf,sizeof(stringf), "{FFFFFF}Agency: {4747A3}Los Santos Police Departament\n{FFFFFF}Addressee:{4747A3} %s\n{FFFFFF}Fine Inssuer: {4747A3} %s \n\n", sendername,FinesInfo[playerid][listitem][fPolitist]);
format(stringf2,sizeof(stringf2), "{FFFFFF}Amount:{4747A3}$%d\n{FFFFFF}Reason:{4747A3} %s\n",FinesInfo[playerid][listitem][fPret],FinesInfo[playerid][listitem][fPentru]);
Those should be loaded or store to them according to the fine ID.
Reply
#10

He dont show.I need a code to Take the rows from mySQL tu The case of dialog. I make The code,but is showed just 1 ticket. And i want to show max 10 tickets.Your code dont give any warning, but he dont show
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)