AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get unique table id? (https://forums.alliedmods.net/showthread.php?t=308141)

jonatat 06-08-2018 08:17

How to get unique table id?
 
Hello folks. I want to made custom info. Like current score in server.

I have table row with id 24 (like example. every time then maps reload its create a new id)

My code looks like that:

PHP Code:

public UpdateGameLIVE(id)
{
new 
szQuery[3800];

formatexszQuery3799"UPDATE `matches` SET `left_score` = '%d', `right_score` = '%d' WHERE id = '%d';"scoreCTSscoreTSid);
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);


But its does not working. Sorry for bad english. Any help?

jonatat 06-08-2018 10:55

Re: How to get unique table id?
 
PHP Code:

public UpdateGameLIVE(id)
{
new 
szQuery[3800];
new 
match_id SQL_GetInsertId(szQuery);

formatexszQuery3799"UPDATE `matches` SET `left_score` = '%d', `right_score` = '%d' WHERE match_id = '%d';"scoreCTSscoreTSmatch_id);
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);


But getting error then compiling. Any ideas?

CrazY. 06-08-2018 11:44

Re: How to get unique table id?
 
Give us informations about this compiling error that you're getting.

jonatat 06-08-2018 11:49

Re: How to get unique table id?
 
Quote:

Originally Posted by CrazY. (Post 2595843)
Give us informations about this compiling error that you're getting.

Thanks for answer CrazY!

Compiling dont giving any error after update:

PHP Code:

public UpdateGameLIVE(id)
{
new 
szQuery[3800];
new 
match_id SQL_GetInsertIdg_hTuple );

formatexszQuery3799"UPDATE `matches` SET `left_score` = '%d', `right_score` = '%d' WHERE match_id = '%d';"scoreCTSscoreTSmatch_id);
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery);


But now i'm getting error in server:
PHP Code:

[MySQLInvalid query handle

PHP Code:

[AMXXRun time error 10native error (native "SQL_GetInsertId"


CrazY. 06-08-2018 11:53

Re: How to get unique table id?
 
Try this.

Code:
formatex( szQuery, 3799, "UPDATE matches SET left_score = '%i', right_score = '%i' WHERE match_id = '%i';", scoreCTS, scoreTS, match_id);

But the real problem is in your g_hTuple. Are you sure the connection was made successfully? Also, SQL_GetInsertId will return 0 if you not use INSERT query before.

Natsheh 06-08-2018 12:00

Re: How to get unique table id?
 
Show full code

jonatat 06-08-2018 12:02

Re: How to get unique table id?
 
Quote:

Originally Posted by CrazY. (Post 2595846)
Try this.

Code:
formatex( szQuery, 3799, "UPDATE matches SET left_score = '%i', right_score = '%i' WHERE match_id = '%i';", scoreCTS, scoreTS, match_id);

But the real problem is in your g_hTuple. Are you sure the connection was made successfully? Also, SQL_GetInsertId will return 0 if you not use INSERT query before.

Thanks CrazY. My insert into looks like that:

PHP Code:

formatex(szQuery3799"INSERT INTO matches (`match_id`, `map`, `played_at`, `left_score`, `right_score`, `state`, `server`, `left_team_id`, `right_team_id`, `game_id`) VALUES ('%s', '%s', NOW(), '0', '0', '0', 'cs.bigmatches.me', '1', '1', '3');"match_idmap_name); 

Also g_hTuple:

PHP Code:

public MySQLx_Init()
{    
g_hTuple SQL_MakeDbTuple(GAME_HOSTGAME_USERGAME_PASSWORDGAME_DATABASE);

for(new 
0sizeof szTablesi++)
{
SQL_ThreadQuery(g_hTuple"QuerySetData"szTables[i]);
}



CrazY. 06-08-2018 12:57

Re: How to get unique table id?
 
Hm... that's weird. If you do not want to share the source code with us, I suggest you to take a look at this.

https://forums.alliedmods.net/showth...p?t=172936#SQL

jonatat 06-09-2018 07:26

Re: How to get unique table id?
 
1 Attachment(s)
Quote:

Originally Posted by Natsheh (Post 2595850)
Show full code

Quote:

Originally Posted by CrazY. (Post 2595864)
Hm... that's weird. If you do not want to share the source code with us, I suggest you to take a look at this.

https://forums.alliedmods.net/showth...p?t=172936#SQL

Attached


All times are GMT -4. The time now is 04:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.