Raised This Month: $ Target: $400
 0% 

SQLX How to get coluumn with highest number?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gameplayonline
Member
Join Date: Jun 2017
Old 06-30-2017 , 12:07   SQLX How to get coluumn with highest number?
Reply With Quote #1

Please How i can do this:
From mysql get column 1 with row where is saved highest number and save it to local variable
if i have in column 1 10 rows and have saved data 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 i need get 10 if i will add 11 i need get 11...

Last edited by gameplayonline; 06-30-2017 at 12:28.
gameplayonline is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-30-2017 , 12:32   Re: SQLX How to get coluumn with highest number?
Reply With Quote #2

Code:
SELECT MAX(ColumnName) FROM DatabaseName;

Last edited by klippy; 06-30-2017 at 12:33.
klippy is offline
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
gameplayonline
Member
Join Date: Jun 2017
Old 07-01-2017 , 22:01   Re: SQLX How to get coluumn with highest number?
Reply With Quote #4

If it will help somebody i fixed it with this:
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)
	}
	

	new id	
	id = Data[0]
	
	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)
		addId(id)
	} 
	
	else
	{
		client_print(id, print_chat, "Uz si bol zaregistrovany, napis /uid pre zistenie UID")
	}	
	return PLUGIN_CONTINUE
}  

public addId(id)
{
	// READ MAIN DATA
	new Data[1]
	Data[0] = id
			
	// 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 Handle:Query2
	
	
	Query2 = SQL_PrepareQuery(SqlConnection, "SELECT MAX(UID) FROM player")
	SQL_Execute(Query2)
	if(SQL_NumResults(Query2) == 1)
	{
		//.if there are no results found
		new szTemp[512]
		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 num = SQL_ReadResult(Query2, 0)
		client_print(id, print_chat, "num %d", num)
		new addUid = num + 1
		client_print(id, print_chat, "addid +1 = %d", addUid)
		format(szTemp,charsmax(szTemp),"UPDATE `player` SET `UID` = '%d' WHERE `player`.`SteamID` = '%s';", addUid, szSteamId);
		SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
		client_print(id, print_chat, "Uspesne si sa zaregistroval do referral systemu. Napis /uid aby si zistil svoje UID")
		
			
	}
	else
	{
		client_print(id, print_chat, "Chyba")
	}
	SQL_FreeHandle(Query2)
	// you free everything with SQL_FreeHandle
	SQL_FreeHandle(SqlConnection)  
	return PLUGIN_CONTINUE
}
gameplayonline is offline
Reply



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