UPDATE QUERY
#1

Hi there !
I have a problem with some fields.

Some fields are updated but not at all.


I use:

Код HTML:
public SyncTime()
{
	//new string[64];
	new tmphour;
	new tmpminute;
	new tmpsecond;
	new query[1000];
	new query2[1000];
	gettime(tmphour, tmpminute, tmpsecond);
	FixHour(tmphour);
	tmphour = shifthour;
	if ((tmphour > ghour) || (tmphour == 0 && ghour == 23))
	{
		ghour = tmphour;
		PayDay();
		if (realtime)
		{
			SetWorldTime(tmphour);
		}
	}
	if(tmphour == 22 && tmpminute == 58)
	{
	    mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerDonateTime` = `playerDonateTime`+1");
		mysql_tquery(handle, query2);
		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `pZileAmanet` = `pZileAmanet`+1");
		mysql_tquery(handle, query2);
	}
	if(tmphour == 22 && tmpminute == 55)
	{
	    mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerCar1Days` = `playerCar1Days`+1");
		mysql_tquery(handle, query2);

		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerCar2Days` = `playerCar2Days`+1");
		mysql_tquery(handle, query2);

		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerCar3Days` = `playerCar3Days`+1");
		mysql_tquery(handle, query2);

		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerCar4Days` = `playerCar4Days`+1");
		mysql_tquery(handle, query2);
		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerCar5Days` = `playerCar5Days`+1");
		mysql_tquery(handle, query2);
	}
	if(tmphour == 22 && tmpminute == 59)
	{
	    for(new xf = 0; xf < MAX_GROUPS; xf++)
		{
			mysql_format(handle, query, 500, "UPDATE `playeraccounts` SET `playerDays` = `playerDays`+1 WHERE `playerGroup` = '%d'", xf);
			mysql_tquery(handle, query);
			mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `player24` = `player24`+1");
			mysql_tquery(handle, query2);
		}
	}
	if(tmphour == 23 && tmpminute == 0)
	{
		for(new c = 0; c < MAX_CLANS; c++)
		{
			mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerClanDays` = `playerClanDays`+1 WHERE `playerClan` = '%d'", c);
			mysql_tquery(handle, query2);
		}
		mysql_format(handle, query2, 500, "UPDATE `houses` SET `houseLastOn` = `houseLastOn`+1");
		mysql_tquery(handle, query2);
		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `playerAnuntat` = `playerAnuntat`+1");
		mysql_tquery(handle, query2);
		mysql_format(handle, query2, 500, "UPDATE `playeraccounts` SET `samposcop` = `samposcop`+1");
		mysql_tquery(handle, query2);
		mysql_format(handle, query2, 500, "UPDATE `clans` SET `clanDays` = `clanDays`+1");
		mysql_tquery(handle, query2);
	}
}
For example clanDays is not updated, playerCar4Days, playerCar5Days. What's wrong?
Reply
#2

This looks inefficient and it probably is. What do these "player*Days" fields even store? I don't understand the purpose of those loops either since there isn't any additional check taking place. If you want to exclude players that are not in a group/clan you should use
PHP код:
WHERE playerGroup IS NOT NULL 
And then there is of course the completely unnecessary usage of mysql_format because nothing is being formatted.
Reply
#3

So, can I use directly " mysql_tquery(handle, "UPDATE playeraccounts SET playerCar1Days = 'playerCar1Days'+1"); " ?
Reply
#4

Use mysql_query not mysql_tquery.
mysql_tquery only use for callbacks.
Reply
#5

Quote:
Originally Posted by haikalbintang
Посмотреть сообщение
Use mysql_query not mysql_tquery.
mysql_tquery only use for callbacks.
for callbacks? what do you mean? ?

I found it:

forward OnPlayerDataLoaded(playerid);

Код HTML:
public OnPlayerConnect(playerid)
{
	new query[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pname, sizeof(pname));
	mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%e'", pname);
	mysql_tquery(MySQL, query, "OnPlayerDataLoaded", "d", playerid);
	return 1;
}
 
public OnPlayerDataLoaded(playerid)
{
	//Query processed, you can now execute cache functions (like cache_get_row) here.
	new NumRows = cache_num_rows();
	printf("There are %d players with the same name.", NumRows);
	return 1;
}
Thanks !
Reply
#6

Quote:
Originally Posted by haikalbintang
Посмотреть сообщение
Use mysql_query not mysql_tquery.
mysql_tquery only use for callbacks.
This is an illogical argument. mysql_tquery isn't forcing you to call a callback, you can leave the callback param null if you don't want anything called.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)