MySQL - What are rows and fields?
#1

Код:
cache_get_field_content_int(row, const field_name[], connectionHandle = 1)
The above line of code is what I am using multiple times. Below is part of my code:

Код:
PlayerInfo[playerid][pSpawn] = cache_get_field_content_int(0, "Spawn");
PlayerInfo[playerid][pGender] = cache_get_field_content_int(0, "Gender");
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
PlayerInfo[playerid][pEntered] = cache_get_field_content_int(0, "Entered");
PlayerInfo[playerid][pMinutes] = cache_get_field_content_int(0, "Minutes");
PlayerInfo[playerid][pTMinutes] = cache_get_field_content_int(0, "TMinutes");
PlayerInfo[playerid][pHours] = cache_get_field_content_int(0, "Hours");
PlayerInfo[playerid][pAge] = cache_get_field_content_int(0, "Age");
PlayerInfo[playerid][pADMute] = cache_get_field_content_int(0, "ADMute");
PlayerInfo[playerid][pModel] = cache_get_field_content_int(0, "Model");
PlayerInfo[playerid][pModel1] = cache_get_field_content_int(0, "Model1");
PlayerInfo[playerid][pModel2] = cache_get_field_content_int(0, "Model2");
PlayerInfo[playerid][pModel3] = cache_get_field_content_int(0, "Model3");
PlayerInfo[playerid][pMapper] = cache_get_field_content_int(0, "Mapper");
PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "Banned");
PlayerInfo[playerid][pNumber] = cache_get_field_content_int(0, "Number");
PlayerInfo[playerid][pKill] = cache_get_field_content_int(0, "Kill");
PlayerInfo[playerid][pDeath] = cache_get_field_content_int(0, "Death");
PlayerInfo[playerid][pInt] = cache_get_field_content_int(0, "Interior");
PlayerInfo[playerid][pVW] = cache_get_field_content_int(0, "Virtual World");
I have over 150 lines of the above code for all my different variables and strings. I set the row to 0 at first not knowing what it was, but since the code is not loading, I think it has something to do with that. Can someone help?


EDIT:
Also, is this the most efficient way of saving everything?

Код:
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `VehVW`=%d, `WalkStyle`=%d, `Fac`=%d, `FacRank`=%d, `FacLeader`=%d, 'FacDiv'=%d, 'FacDivLeader'=%d, 'FacDuty'=%d, 'Weapon[0]'=%d, 'Weapon[1]'=%d WHERE `ID`=%d",
PlayerInfo[playerid][pVehVW], PlayerInfo[playerid][pWalkStyle], PlayerInfo[playerid][pFac], PlayerInfo[playerid][pFacRank], PlayerInfo[playerid][pFacLeader], PlayerInfo[playerid][pFacDiv], PlayerInfo[playerid][pFacDivLeader], PlayerInfo[playerid][pFacDuty], PlayerInfo[playerid][pWeapon][0], PlayerInfo[playerid][pWeapon][1], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");
	
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `Weapon[2]`=%d, `Weapon[3]`=%d, `Weapon[4]`=%d, `Weapon[5]`=%d, `Weapon[6]`=%d, 'Weapon[7]'=%d, 'Weapon[8]'=%d, 'Weapon[9]'=%d, 'Weapon[10]'=%d, 'Weapon[11]'=%d, 'Weapon[12]'=%d WHERE `ID`=%d",
PlayerInfo[playerid][pWeapon][2], PlayerInfo[playerid][pWeapon][3], PlayerInfo[playerid][pWeapon][4], PlayerInfo[playerid][pWeapon][5], PlayerInfo[playerid][pWeapon][6], PlayerInfo[playerid][pWeapon][7], PlayerInfo[playerid][pWeapon][8], PlayerInfo[playerid][pWeapon][9], PlayerInfo[playerid][pWeapon][10], PlayerInfo[playerid][pWeapon][11], PlayerInfo[playerid][pWeapon][12], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");
Again, I use the code above multiple times as it has to cover all my variables.
Reply
#2

When you select a player's data from the database, you know for sure that the max records exist for that player is 1 so the row is 0.

In case you'd select everything from a table and use a loop, the variable is used in the iterator would be the "rowid" instead.

About the not loading part, you'll need to explain more about what actually happens.

EDIT:

The first query is fine, if you remove `` around the fields you can then reduce the size of it.

About the second one, I've never used "name[x]" and I'm not sure if it's acceptable (check mysql logs) but there's a really good tutorial about how to save weapons: https://sampforum.blast.hk/showthread.php?tid=505081
Reply
#3

The saving part only saves the first set. So, for example:

Код:
new query[518];
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `Admin`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f WHERE `ID`=%d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pX], PlayerInfo[playerid][pY], PlayerInfo[playerid][pZ], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");

mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `Gender`=%d, `Level`=%d, `Entered`=%d, `Minutes`=%d, `TMinutes`=%d, 'Hours'=%d, 'Age'=%d, 'Bank'=%d, 'Model'=%d, 'Model1'=%d WHERE `ID`=%d",
PlayerInfo[playerid][pGender], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pEntered], PlayeInfo[playerid][pMinutes], PlayerInfo[playerid][pTMinutes], PlayerInfo[playerid][pHours], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pModel], PlayerInfo[playerid][pModel1], PlayerInfo[playerid][ID]);
mysql_tquery(mysql, query, "", "");
These two are at the top of the stock that saves all my variables when the player logs out. It only saves the first set, so like the Admin, posX, PosY ect... is saved, but the Gender, Hours, Level is not.

I'm having a problem with the Gender especially. When they select their gender, I do:

Код:
PlayerInfo[playerid][pGender] = 1; //male
And when they log out the stock above is called so that it saves it but when I check the database it's not saved.
Reply
#4

"... 'Hours'=%d, 'Age'=%d, 'Bank'=%d, 'Model'=%d, 'Model1'=%d ..."

You used '' around the fields name instead of ``.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
"... 'Hours'=%d, 'Age'=%d, 'Bank'=%d, 'Model'=%d, 'Model1'=%d ..."

You used '' around the fields name instead of ``.
Shit. How do you do that little one?

EDIT: Got it.
Reply
#6

No need to use any grave accent:
pawn Код:
"UPDATE users SET Gender=%d, Level=%d, Entered=%d, Minutes=%d, TMinutes=%d, Hours=%d, Age=%d, Bank=%d, Model=%d, Model1=%d WHERE ID=%d"
Reply
#7

Код:
PlayerInfo[playerid][pSpawn] = cache_get_field_content_int(0, "Spawn");
PlayerInfo[playerid][pGender] = cache_get_field_content_int(0, "Gender");
PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
PlayerInfo[playerid][pEntered] = cache_get_field_content_int(0, "Entered");
PlayerInfo[playerid][pMinutes] = cache_get_field_content_int(0, "Minutes");
PlayerInfo[playerid][pTMinutes] = cache_get_field_content_int(0, "TMinutes");
PlayerInfo[playerid][pHours] = cache_get_field_content_int(0, "Hours");
PlayerInfo[playerid][pAge] = cache_get_field_content_int(0, "Age");
PlayerInfo[playerid][pADMute] = cache_get_field_content_int(0, "ADMute");
PlayerInfo[playerid][pModel] = cache_get_field_content_int(0, "Model");
PlayerInfo[playerid][pModel1] = cache_get_field_content_int(0, "Model1");
PlayerInfo[playerid][pModel2] = cache_get_field_content_int(0, "Model2");
PlayerInfo[playerid][pModel3] = cache_get_field_content_int(0, "Model3");
PlayerInfo[playerid][pMapper] = cache_get_field_content_int(0, "Mapper");
PlayerInfo[playerid][pBanned] = cache_get_field_content_int(0, "Banned");
PlayerInfo[playerid][pNumber] = cache_get_field_content_int(0, "Number");
PlayerInfo[playerid][pKill] = cache_get_field_content_int(0, "Kill");
PlayerInfo[playerid][pDeath] = cache_get_field_content_int(0, "Death");
PlayerInfo[playerid][pInt] = cache_get_field_content_int(0, "Interior");
PlayerInfo[playerid][pVW] = cache_get_field_content_int(0, "Virtual World");
With using this, is there something I need to use to define what user to save it to? Like an ID for something?
I use an ID to define the saving, should it be the same for loading?

Like:
Код:
WHERE `ID`=%d"
Reply
#8

When a player connects, the only thing you know is their name, not their unique ID to the database so you'll use the name for loading and ID for saving (like you have it most likely).
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
When a player connects, the only thing you know is their name, not their unique ID to the database so you'll use the name for loading and ID for saving (like you have it most likely).
No, I dont. How do I add that? I have a unique ID for each account saved in PlayerInfo[playerid][ID]. How do I use it?
Reply
#10

You already do. You save (UPDATE query) using the ID at WHERE clause.
Reply


Forum Jump:


Users browsing this thread: