Mysql - read value from Table WHERE id=x - 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: Mysql - read value from Table WHERE id=x (
/showthread.php?tid=575968)
Mysql - read value from Table WHERE id=x -
CaTaLinU - 31.05.2015
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
Код:
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
Код:
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...
Re: Mysql - read value from Table WHERE id=x -
Konstantinos - 31.05.2015
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.
Re: Mysql - read value from Table WHERE id=x -
CaTaLinU - 01.06.2015
Thank you very much and sorry for this wrong section in wich i've posted my thread.
Hace a good day .