Getting selected MySQL Table/Row(s), and converting it all into LUA Tables.
1 replies, posted
Hi, I'm having a bit of troubles finding a method to get a row, or all rows and put them into a table via LUA.
<MySQL functions, query stuff here>
BannedPlayers[MySQL Table Item 1] + { blah = admin_name, blahb = player_name }
I've got all the MySQL things setup, I just need to find a way to receive, and convert the rows into tables. Thanks for all the help!
#PowerofScience
Import the tables you need and use plenty of PrintTable on the tables coming from SQL to get a good idea of the structure.
function GM:PlayerAuthed(ply, steamid, uniqueid)
local query = "SELECT * FROM bans WHERE steamid = '"..ply:SteamID64().."'"
GetDataQuery(query, function(tbl)
if tbl[1] == nil then return end
local bantime = tbl[1].bantime
local banduration = tbl[1].banduration
if banduration == 0 then
ply:Kick("You are permanently banned.")
end
local minuteduration = (bantime+banduration-os.time())/60
if os.time() < bantime+banduration then
ply:Kick("Banned for "..parseAdminTime(minuteduration))
return
elseif os.time() > bantime+banduration then
Query("DELETE FROM bans WHERE steamid = '"..ply:SteamID64().."'")
return
end
end)
end
Here's an example from my ban system that will maybe give you an idea of the structure of SQL data. In this table there are only 3 columns, steamid64, the time the ban happened in unix time and the duration of the ban in seconds.
Sorry, you need to Log In to post a reply to this thread.