Get Table Values

Hello guys, well i’ve been looking for this for a long time and i’ve been trying to do this but i CAN’T :frowning: That’s why im here asking for this :D, if anyone know how to do this and share it with facepunch & i , i would be really happy :).

The thing is that i’ve a mysql connection with a table with the rows: steamid, name, money.

The thing is that i’ve been trying to retrieve the money value wich is 1 for example as an INT value, like get the money row only, not the whole table… i can insert values properly, but i can’t retrieve values in game…

Any idea of how i can retrieve the money table value?

Table: Info
Rows: SteamID, Name, Money

Thanks !

Do you know how to connect to the database and execute a query?

Here is a tutorial on basic query formats: https://dl.dropboxusercontent.com/u/26074909/tutoring/database/basic_queries_and_query_formats_used_to_check_for_existing_row.lua.html

You’d use: local _q = “SELECT Money FROM Info WHERE SteamID=” … SQLStr( _p:SteamID( ) ) … " LIMIT 1";

And run that through your DATABASE_REFERENCE:Query, or different function depending on which database module you’re using.

If you’re using TMySQL then by default the result row keys will be numeric. If you want it to act the same was as MySQLOO and return the key as a string “Money”, then you can add a flag right after the “on success” function callback: QUERY_FLAG_ASSOC

So it’d just be local _money = tonumber( _row[ 1 ].Money ); – regardless of if using TMySQL or MySQL.

If you don’t use the flag and you’re using TMySQL it’d be: local _money = tonumber( _row[ 1 ][ 1 ] );

Additionally, depending on how much currency you can gain and how quickly you gain it, INT is limited to around -2.14 billion to +2.14 billion. While it should be more than enough, some cases it may not be.

Hopefully this helps.