enum Data { name[24], pass[32], money } new PlayerInfo[MAX_PLAYERS][Data]; on query execute: format: "SELECT * FROM `users` WHERE NAME = 'n0minal'; then send mysql query, store data and retrieve row use sscanf(query, "all formats for enum here", PlayerInfo[playerid]); Is possible with cache or i have to do like: PlayerInfo[playerid][name] = cache_get_content(bla bla bla bla); |
There is some way to get cache fields result and sscanf it to an enum?
Like i was doing on R6 using mysql_store_result + retrieve row then sscanf all recieved data for enum... Or i have to do it manually? Ex: |
There is some way to get cache fields result and sscanf it to an enum?
Like i was doing on R6 using mysql_store_result + retrieve row then sscanf all recieved data for enum... Or i have to do it manually? Ex: |
enum Data
{
name[24],
pass[32],
money
}
new PlayerInfo[MAX_PLAYERS][Data];
function SQL_GetsInf(...){
for(new q; q < 1; q++){
sscanf(Data, "p<§>s[24]s[32]d",PlayerInfo[q]);
printf("%s",PlayerInfo[i][name]);
printf(...);
}
return true;
}
You don't need to use sscanf to store the result, just use cache_get_* natives to get your data.
I'd recommend checking out this tutorial (click me) by AndreT. |
public OnDataLoad() { new rows = cache_num_rows(), fields = cache_num_fields(); for(new r; r < rows; r++) { new data[2048], field_tmp[128]; for(new f; f < fields; f++) { cache_get_row(r, f, field_tmp); if(f != 0) strcat(data, "|"); strcat(data, field_tmp); } sscanf(data, "...", PlayerData[r]); } }
You can now access every row independently by its index through cache_get_row and cache_get_field_content.
What was Код:
new data[4]; new row_data[128]; while(mysql_fetch_row_format(row_data)) { sscanf("p<|>...", data[0], data[1], ...); } Код:
new data[4]; for(new r=0; r < cache_num_rows(); r++) { data[0] = cache_get_row_int(r, 0); //store the first field (index '0') into data[0] data[1] = cache_get... } |
Okay, tried this but this makes the script stuck. As in it doesnt advance on, I am printing "Loading bla bla" and once everything is loaded I print "Loaded bla bla" but with the code you gave it doesnt proceed ahead from "Loading bla bla". Any reasons or whatever ?
|
if(mysql_num_rows()) { if(mysql_retrive_row()) { mysql_fetch_field_row(dbQUERY, "ID"); Korisnik[playerid][kID] = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Novac"); Korisnik[playerid][kNovac] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "Spol"); _HRP_kSpol{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Godine"); _HRP_kGodine{playerid} = strval(dbQUERY); mysql_fetch_field_row(Korisnik[playerid][kGPCI], "GPCI"); mysql_fetch_field_row(Korisnik[playerid][kRegistracijski_Kod], "Reg_Kod"); mysql_fetch_field_row(Korisnik[playerid][kIP], "IP"); mysql_fetch_field_row(dbQUERY, "Skin"); Korisnik[playerid][kSkin] = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Staff"); _HRP_kStaff{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Dan"); _HRP_kDan{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Mjesec"); _HRP_kMjesec{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Godina"); Korisnik[playerid][kGodina] = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Sat"); _HRP_kSat{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Minuta"); _HRP_kMinuta{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Sekunda"); _HRP_kSekunda{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Mute"); Korisnik[playerid][kMute] = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Online_Brojac"); Korisnik[playerid][kOnline_Counter] = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Melee"); _HRP_kMelee{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Melee_Municija"); _HRP_kMelee_Ammo{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Pistolj"); _HRP_kPistol{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Pistolj_Municija"); _HRP_kPistol_Ammo{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Automatik"); _HRP_kAutomatic{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Automatik_Municija"); _HRP_kAutomatic_Ammo{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Eksploziv"); _HRP_kExplosion{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Eksploziv_Municija"); _HRP_kExplosion_Ammo{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Pistolj_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "Shotgun_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "UZI_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "Automatik_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "Rifle_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY); mysql_fetch_field_row(dbQUERY, "Kickova"); _HRP_kKickova{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Banova"); _HRP_kBanova{playerid} = strval(dbQUERY); mysql_fetch_field_row(dbQUERY, "Warnova"); _HRP_kWarnova{playerid} = strval(dbQUERY); } } mysql_free_result();
Hi, I'm new in MySQL(R39-2) and I don't know how to load strings, ints and floats from database... I made code by some tutorial from 2012(R7 is used in tutorial). I made this:
I got 26 errors because ''mysql_fetch_field_row'' isn't defined. So, how I can load field then? |
I don't understand why I need use loop :/
I just need load files of logged player, if u understand me |
mysql_tquery(handle, "SELECT ....", "OnLoadData", "i", playerid);
forward OnLoadData(playerid);
public OnLoadData(playerid)
{
if(cache_get_row_count())
{
// string
cache_get_field_content(0, "Name", PlayerInfo[playerid][name]); /* OR */ cache_get_row(0, 0, PlayerInfo[playerid][name]);
// integer
PlayerInfo[playerid][money] = cache_get_field_content_int(0, "Money"); /* OR */ PlayerInfo[playerid][money] = cache_get_row_int(0, 1);
// float
PlayerInfo[playerid][health] = cache_get_field_content_float(0, "HP"); /* OR */ PlayerInfo[playerid][health] = cache_get_row_float(0, 2);
// continue...
}
else
{
// no data found.. registration stuff here maybe?
}
return true;
}
mysql_format(_HRP_srv_db_conn, sifra, 86, "SELECT * FROM `"_USER_DB"` WHERE Ime = '%e'", _name); mysql_tquery(_HRP_srv_db_conn, sifra, "_HRP_LoadUser", "dd", playerid, false); { ... } Korisnik[playerid][kID] = cache_get_field_content(dbQUERY, "ID");
It'll aThen it'll be like this?
Код:
mysql_format(_HRP_srv_db_conn, sifra, 86, "SELECT * FROM `"_USER_DB"` WHERE Ime = '%e'", _name); mysql_tquery(_HRP_srv_db_conn, sifra, "_HRP_LoadUser", "dd", playerid, false); { ... } Korisnik[playerid][kID] = cache_get_field_content(dbQUERY, "ID"); |
I don't know what now... I got undefined symbols ''mysql_store_result'' and ''mysql_num_rows'' and ''mysql_retrive_row'' and ''mysql_free_result''....
|
loadStuff()
{
new rows, fields;
print("==> Loading the Required Items.");
cache_get_data(rows, fields);
if(!rows)
{
print("ERROR: The Table you called the query on can't be found. Skipping the loading.");
}
else
{
if(rows > MAX_CHECKS)
{
print("ERROR: Limit exceeded.");
return 1;
}
for(new i = 0; i < rows; i++)
{
cache_get_field_content(i, "Name", stuffInfo[i][Name], mysql, 60);
cache_get_field_content(i, "stuffC", string, mysql, 30); //string declared before the start of the callback.
stuffInfo[i][ID] = cache_get_field_content_int(i, "stuffID");
}
printf("==> Loaded %i of the required stuff", rows);
}
return 1;
}