SA-MP Forums Archive
UPDATE QUERY - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: UPDATE QUERY (/showthread.php?tid=627923)



UPDATE QUERY - Nin9r - 03.02.2017

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?


Re: UPDATE QUERY - Vince - 03.02.2017

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.


Re: UPDATE QUERY - Nin9r - 03.02.2017

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


Re: UPDATE QUERY - haikalbintang - 04.02.2017

Use mysql_query not mysql_tquery.
mysql_tquery only use for callbacks.


Re: UPDATE QUERY - Nin9r - 05.02.2017

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 !


Re: UPDATE QUERY - Abagail - 05.02.2017

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.