17.09.2016, 10:01
I want to retrieve multiple rows from my table and then split the data into a list for a character menu. I just can't get my head around how to do it in R40. Any Ideas? Cheers.
for (new i, j = cache_num_rows(); i != j; i++)
{
// cache functions to retrieve the data.
// "i" will be the rowid.
}
// 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
}