Raised This Month: $ Target: $400
 0% 

SQLX How to get coluumn with highest number?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
gameplayonline
Member
Join Date: Jun 2017
Old 07-01-2017 , 03:47   Re: SQLX How to get coluumn with highest number?
Reply With Quote #3

I have this but its not working. Its set UID to 0 and if will work this new num = SQL_ReadResult(Query2, 0)
new addUid = num + 1
it must be 1 because default it get 0

Code:
public register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
	if(FailState == TQUERY_CONNECT_FAILED)
	{
		log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error)
	}
	else if(FailState == TQUERY_QUERY_FAILED)
	{
		log_amx("Load Query failed. [%d] %s", Errcode, Error)
	}
	

			
	// ok, we're ready to connect
	new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
	if(SqlConnection == Empty_Handle)
	// stop the plugin with an error message
	set_fail_state(g_Error)
	
	new id	
	id = Data[0]
	
	new Handle:Query2
	new Handle:Query3
	
	
	
	if(SQL_NumResults(Query) < 1) 
	{
		//.if there are no results found
		new szSteamId[32]
		get_user_authid(id, szSteamId, charsmax(szSteamId)) // get user's steamid
		
		//  if its still pending we can't do anything with it
		if (equal(szSteamId,"ID_PENDING"))
			return PLUGIN_HANDLED
		
		new szTemp[512]
		
		// now we will insturt the values into our table.
		format(szTemp,charsmax(szTemp),"INSERT INTO `player` ( `SteamID` , `UID`, `Referrals`, `isReferral`)VALUES ('%s','%d','%d','%d');",szSteamId, uid, referrals, isReferral)
		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
		
		Query2 = SQL_PrepareQuery(SqlConnection, "SELECT MAX(UID) FROM player")
		SQL_Execute(Query2)
		if(SQL_NumResults(Query2) == 1)
		{
			get_user_authid( id, steamID, charsmax(steamID)) 
		
			//  if its still pending we can't do anything with it
			if (equal(steamID,"ID_PENDING"))
				return PLUGIN_HANDLED
			
			new num = SQL_ReadResult(Query2, 0)
			new addUid = num + 1
			Query3 = SQL_PrepareQuery(SqlConnection, "UPDATE `player` SET `UID` = '%d' WHERE (`player`.`SteamID` = '%s';",addUid, steamID);
			SQL_Execute(Query3);
			client_print(id, print_chat, "Uspesne si sa zaregistroval do referral systemu. Napis /uid aby si zistil svoje UID")
			SQL_FreeHandle(Query2)
			SQL_FreeHandle(Query3)
		}
		else
		{
			client_print(id, print_chat, "Chyba")
		}
	} 
	
	else
	{
		client_print(id, print_chat, "Uz si bol zaregistrovany, napis /uid pre zistenie UID")
	}	
	return PLUGIN_HANDLED
}

Last edited by gameplayonline; 07-01-2017 at 05:23.
gameplayonline is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:45.


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