MySQL R40 - Retrieving Multiple Rows and Splitting Data
#6

When a player registers the main account and gets the unique ID (from auto increment) and then creates the first character, use the ID instead of the name in "characters" table.

pawn Код:
// OnPlayerConnect:
mysql_format(..., "SELECT character_name FROM characters c JOIN players p ON p.id=c.id WHERE username='%e'", ...);
mysql_tquery(..., "OnPlayerCharactersLoad", "i", playerid);

// OnPlayerCharactersLoad:
new string[150], char_name[MAX_PLAYER_NAME]; // increase "string" if necessary
for (new i, j = cache_num_rows(); i != j; i++)
{
    // retrieve character name - fieldid is 0 as we selected only one field
    cache_get_value(i, 0, char_name);

    // "join" it to the string
    strcat(string, char_name);
    strcat(string, "\n");
    // next line added
}

// the last option (item) of the dialog will be to create a new character
strcat(string, "Create Character");

// OnDialogResponse:
if (!strcmp(inputtext, "Create Character"))
{
    // creating new character..
}
else
{
    // load all the data from the character selected
    mysql_format(..., "SELECT * FROM characters WHERE character_name='%e' LIMIT 1", inputtext);
    mysql_tquery(...);
    // in the specified callback, retrieve all the data for the selected character
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)