MySQL Return data issue -
Alex_T - 18.04.2017
Hey I think my brain is either dieing or something but I am stumped on something that seems easy I just cant think rn. Anyways
I want to retrieve a players name from a mysql table from ID and return their name to use in a command.
Код:
forward OnLookUpVeh(playerid, plate[]);
public OnLookUpVeh(playerid, plate[])
{
new rows,fields;
cache_get_data(rows,fields);
new id_string[128], carname[48],owner, owner2[MAX_PLAYER_NAME], buytime[128], msg[128];
cache_get_row(0, 0, id_string);
format(carname, sizeof(carname), "%s", VehiclesName[strval(id_string)-400]);
cache_get_row(0,1, id_string);
owner = strval(id_string);
cache_get_row(0,2, buytime);
GetNameFromCharID(owner);//Where I want to retrieve the name from
cache_get_row(0,0, owner2);
format(owner2, sizeof(owner2), "%s", strval(owner2));
format(msg, sizeof(msg), "Car Name: %s | Owner: %d | Purchased: %s", carname, 0, ReturnDate(buytime));
return 1;
}
Код:
stock GetNameFromCharID(charid)
{
new query[512];
mysql_format(MySQLCon, query, 512, "SELECT `username` FROM `characters` WHERE `ID` = %d LIMIT 1", charid);
return mysql_tquery(MySQLCon, query, "EmptyCallback", "");
}
Re: MySQL Return data issue -
CaRaM3LL - 18.04.2017
Why EmptyCallback ?
You need a public to retrieve de data.
Re: MySQL Return data issue -
Alex_T - 18.04.2017
idk why not, the problem is I have to either send to it over to a Public which you cant return an array in a public, so thats where my problem is.
Re: MySQL Return data issue -
CaRaM3LL - 18.04.2017
Код:
stock LoadCurseFMACheckpoints(idcursa)
{
new query[MAXO_TEXT];
mysql_format(connectionHandle, query, sizeof(query), "SELECT X,Y,Z FROM Races_checkpoints WHERE IDCursa = %d", idcursa);
mysql_tquery(connectionHandle, query, "LoadRacesCheckpoints", "d", idcursa);
return 1;
}
function LoadRacez2()
{
new rows = cache_num_rows();
if(rows)
{
for(new r; r < rows; r++) {
Race[r][IDCursaDB] = cache_get_row_int(r, 1);
cache_get_row(r, 2, Race[r][Nome], .max_len = MAX_PLAYER_NAME); // race name
Race[r][Laps] = cache_get_row_int(r, 3);
Race[r][Costs] = cache_get_row_int(r, 4);
Race[r][Record] = cache_get_row_int(r, 5);
cache_get_row(r, 6, Race[r][RacePLRecord], .max_len = MAX_PLAYER_NAME); // player record
cache_get_row(r, 7, Race[r][RCreator], .max_len = MAX_PLAYER_NAME); // player record
Race[r][Chase] = cache_get_row_int(r, 8);
// iar acum urmeaza sa ii incarcam coordonatele cursei 'r'
LoadCurseFMACheckpoints®;
}
} else printf("No FMA Races loaded from table Races_id.");
return 1;
}
This is how i can retrieve de data.
You can do as well like me but you need to save somehow the data needed.
Re: MySQL Return data issue -
CaRaM3LL - 18.04.2017
Код:
stock GetNameFromCharID(charid)
{
new query[512];
mysql_format(MySQLCon, query, 512, "SELECT `username` FROM `characters` WHERE `ID` = %d LIMIT 1", charid);
return mysql_tquery(MySQLCon, query, "PlayerData", "charid");
}
forward PlayerData(charid);
public PlayerData(charid)
{
new rows = cache_num_rows(), NameStored[MAX_PLAYER_NAME];
if(rows)
{
cache_get_row(0, 0, NameStored, .max_len = MAX_PLAYER_NAME);
}
return 1;
}
Something like that i think.
You can use the stock here:
Код:
forward OnLookUpVeh(playerid, plate[]);
public OnLookUpVeh(playerid, plate[])
{
GetNameFromCharID(owner);//Where I want to retrieve the name from
// and then you can use that NameStored .. but define global NameStored[playerid] something like that
new rows,fields;
cache_get_data(rows,fields);
new id_string[128], carname[48],owner, owner2[MAX_PLAYER_NAME], buytime[128], msg[128];
cache_get_row(0, 0, id_string);
format(carname, sizeof(carname), "%s", VehiclesName[strval(id_string)-400]);
cache_get_row(0,1, id_string);
owner = strval(id_string);
cache_get_row(0,2, buytime);
//GetNameFromCharID(owner);//Where I want to retrieve the name from
cache_get_row(0,0, owner2);
format(owner2, sizeof(owner2), "%s", strval(owner2));
format(msg, sizeof(msg), "Car Name: %s | Owner: %d | Purchased: %s", carname, 0, ReturnDate(buytime));
return 1;
}