#1

Код:
SaveAchievements(playerid)
{
	new _query[74];
	
	mysql_format(handle, _query, sizeof(_query), "DELETE FROM `achievements` WHERE `Username` = %s",  pInfo[playerid][pUsername]);
	mysql_tquery(handle, _query);

	for(new i; i<sizeof(AchievementInfo); i++)
	{
		if(pAch[playerid][E_PlayerAchievements:i])
		{
			mysql_format(handle, _query, sizeof(_query), "INSERT INTO `achievements` (`AchID`) VALUES (%d)", i);
			mysql_tquery(handle, _query);
		}
	}

	return 1;
}
So the thing is it does not work correctly. It saves the achievement into the "AccountID". But the value saving into "AccountID" is the playerid in the game. Like, you're number on /pm [id]. I want it to get the accountid from the table "accounts".


Like, I got an achievement. My Username is DarkMythHunter and my id is 1. I would like the achievement data to be saved into mysql. I want to get the ID, and save it in achievement table. Same for username.


The table achievement have 3 row;

AccountID
Username
AchID


If user DarkMythHunter got an achievement, then his ID in the database, not the ID ingame will be into "AccountID", the username will be under "Username".

Im not that good explaining this one, sorry. Thanks for those who will help me out.
Reply
#2

Add a variable where you store the database ID when the player connects, for example pInfo[playerid][pDBID]

Then you can use it like this:
PHP код:
mysql_format(handle_querysizeof(_query), "INSERT INTO `achievements` (`AchID`,`AccountID`,`Username`) VALUES (%d,%d,%s)"ipInfo[playerid][pDBID], pInfo[playerid][pUsername]);
            
mysql_tquery(handle_query); 
Reply
#3

Wasn't there a variable that store players' IDs? has been a long time since I last looked at the source code.
Reply
#4

When passing a string in a SQL query without apostrophes around, it will result in syntax error.

The important question however is why do you execute a DELETE query every time you want to insert a new achievement for a player and save all achievements at once. When a player connects, you know what achievements they have and when a new achievement is rewarded to them, you know its AchID too. One INSERT query is more than enough.

There are two more things I want to mention. You only select based on player's name when they connect to find out if they are registered. From this point on, you should have stored the account ID (from auto increment when they registered) and use THIS as reference to the player.

The last thing is duplicates. You know AccountID therefore you know the name of the player too. Is there a specific reason you store both account ID and user name at the achievements table? What if a player wants to change their in-game name? Will you update every single table that happens to store the username for not apparent reason? More work for you, honestly.
Reply
#5

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
When passing a string in a SQL query without apostrophes around, it will result in syntax error.

The important question however is why do you execute a DELETE query every time you want to insert a new achievement for a player and save all achievements at once. When a player connects, you know what achievements they have and when a new achievement is rewarded to them, you know its AchID too. One INSERT query is more than enough.

There are two more things I want to mention. You only select based on player's name when they connect to find out if they are registered. From this point on, you should have stored the account ID (from auto increment when they registered) and use THIS as reference to the player.

The last thing is duplicates. You know AccountID therefore you know the name of the player too. Is there a specific reason you store both account ID and user name at the achievements table? What if a player wants to change their in-game name? Will you update every single table that happens to store the username for not apparent reason? More work for you, honestly.
Код:
SaveAchievements(playerid)
{
	new _query[74];
	

	for(new i; i<sizeof(AchievementInfo); i++)
	{
		if(pAch[playerid][E_PlayerAchievements:i])
		{
			mysql_format(handle, _query, sizeof(_query), "INSERT INTO `Achievements` (`AchID`) VALUES (%d)", i);
			mysql_tquery(handle, _query);
		}
	}

	return 1;
}
Will this work?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)