SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > 0.3.7 RC Scripting

 
 
Thread Tools Display Modes
Old 31/05/2015, 09:10 AM   #1
CaTaLinU
Big Clucker
 
Join Date: Aug 2011
Posts: 121
Reputation: 0
Default Mysql - read value from Table WHERE id=x

I have table name "factions" and i want to extract the value of a row "groupSlots" WHERE id=1 (for faction id=1)

i've tried this
Code:
stock GetFactionSlots( FactionID )
{
	new szString[ 128 ], Cache: Result, Get[ 2 ], szFacSlots[ MAX_PLAYER_NAME ];
	format( szString, sizeof( szString ), "SELECT `groupSlots` FROM `factions` WHERE `ID` = %d ;", FactionID );
    Result = mysql_query( SQL, szString );
    cache_get_data( Get[ 0 ], Get[ 1 ], SQL );
    if( !Get[ 0 ] ) szFacSlots = "No-One";
   	 else cache_get_field_content( 0, "groupSlots", szFacSlots, SQL, sizeof( szFacSlots ) );
    cache_delete( Result );
	return ( szFacSlots );
}
and in cmd:factions
Code:
new szString[ 1200 ];			
	format( szString, sizeof( szString ), "{0059FF}Police Departament 		{ffffff}-	Lider: %s (%s) - Membri: %d/%d\n", GetFactionLeader( 1 ), IsOnline( GetFactionLeader( 1 ) ), GetFactionMembers( 1 ) , GetFactionSlots( 1 ) );
groupSlots for faction id 1 value is 6
but on server when running "/factions" returns me something else...
CaTaLinU is offline  
Old 31/05/2015, 10:58 AM   #2
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,989
Reputation: 1340
Default Re: Mysql - read value from Table WHERE id=x

First of all, this is has nothing to do with 0.3.7 version. It's a scripting issue; thus it should've been posted in "Scripting Help" section.

Also GetFactionSlots returns the result as a string and you used in the command /factions %d specifier which is for integers. So change it to %s specifier.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System



www.SF-SE.net
play.sf-se.net:7777
Play now!
Konstantinos is offline  
Old 01/06/2015, 09:19 AM   #3
CaTaLinU
Big Clucker
 
Join Date: Aug 2011
Posts: 121
Reputation: 0
Default Re: Mysql - read value from Table WHERE id=x

Thank you very much and sorry for this wrong section in wich i've posted my thread.

Hace a good day .
CaTaLinU is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Table JaKe Elite Scripting Help 5 13/11/2012 07:53 AM
MySQL: Update all values in table from another table kurta999 Scripting Help 8 23/08/2012 08:55 PM
Read name from table and put into '/' - OnPlayerCommand Riddick94 Help Archive 11 23/08/2011 03:44 PM


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.