Filipe Andrade Filipe Andrade - 1 month ago 10
SQL Question

Gmod Lua/Sql Error (attempt to concatenate a table value)

Hey guys I'm having a problem with SQL queries

i have this code:

sql.Query("SELECT hp FROM hp_data WHERE steam = '"..ply:SteamID().."';")


This is the error I get:


"attempt to concatenate a table value"


My table looks like this:

The table is called hp_data

| steam | hp | money |

1|STEAM:0_0_0 | 100 | 500 |


What can I do to make
"sql.Query("SELECT hp FROM hp_data WHERE steam = '"..ply:SteamID().."';")"
return 100 ?

Thanks for reading :)

Answer

There is no problem with the query, the "concatenation" problem is due to assign a var like "var = sql.Query("SELECT hp FROM hp_data WHERE steam = '"..ply:SteamID().."';")" to get the hp value from the database.

You have to do it like this: "sql.Query("SELECT hp FROM hp_data WHERE steam = '"..ply:SteamID().."';", function(return) return[1].hp_data[1].hp end) "

Comments