Mysql Listing problems
#1

Hey i've had ago at making a command that lists all the registered players in the database

Its only shwoing it once and not showing the correct info
pawn Код:
CMD:regedplayers(playerid, params[])
{
    new playerData[512], AccName[100][MAX_PLAYER_NAME], AccIDs, string[512];
    mysql_query("SELECT `AccID`,`Username` FROM `Accounts` ORDER BY `AccID`");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_fetch_row(playerData);
        sscanf(playerData, "is[24]", AccIDs,AccName);
        // do something with 'playersName' and 'playersScore'
        format(string, sizeof(string), "ID: %i Name: %s",AccIDs,AccName);
        //SendClientMessage(playerid, ~1, string);
        ShowPlayerDialog( playerid, 350, DIALOG_STYLE_MSGBOX,"Location: Players", string, "(Close)", "");
    }
    mysql_free_result();
    return 1;
}
Reply
#2

pawn Код:
CMD:regedplayers(playerid, params[])
{
    new playerData[512], AccName[100][MAX_PLAYER_NAME], AccIDs, string[512];
    mysql_query("SELECT `AccID`,`Username` FROM `Accounts` ORDER BY `Accounts`.`AccID`");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_fetch_row(playerData);
        sscanf(playerData, "p<|>is[24]", AccIDs,AccName);
        // do something with 'playersName' and 'playersScore'
        format(string, sizeof(string), "ID: %i Name: %s",AccIDs,AccName);
        SendClientMessage(playerid, ~1, string);
    }
    mysql_free_result();
    return 1;
}
1) I added `Accounts`.`AccID` so it knows how to order them.
2) I also added p<|> into sscanf which means that it will split it where is | sign.
3) I also uncommented SendClientMessage and deleted ShowPlayerDialog.

P.S. This command can crash you. What if you have 1'000 accounts. You will get 1'000 messages which will cause HUGE lag or if you use ShowPlayerDialog it would go off screen (only in case you make that big string, not one that is only 512 chars long)...
Reply
#3

Thanks

Edit: Its only listing two of the four registered players and its the same one twice.
pawn Код:
[14:58:47] ID: 2 Name: AR1566A

[14:58:47] ID: 2 Name: AR1566A
Reply
#4

pawn Код:
while(mysql_retrieve_row())
    {
        mysql_fetch_row(playerData);
This is wrong. You use one or the other, but not both. Both functions advance the row pointer so with every record read, one record will be skipped.

pawn Код:
while(mysql_fetch_row(playerData))
{
Reply
#5

Well i don't get you, Please elaborate on this, Make it clear.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)