Working With MySQL Table Returns

I am trying to grab three fields from my doors table ( EntID, Name, Type ) and then sort them into lua tables depending on their type. Type 1 goes into the closed table, type 2 goes in the public table, and type 3 goes into the admin table. The only values I need in the table are EntID and Name. I am not very fond of tables so I have no Idea how I could use a for loop to lets say get EntID “2” and Name “Admin Door” out of the admin table and apply the name to the entity. I am terrible at explaining so bear with me.

Basic idea, Admin Door:
MySQL
|
Type is 3, put EntID and Name in Admin table
|
Get entity by EntID and setnwstring of that entity to Name from admin table

I am trying to get this to work for multiple doors which can be one of three types.

[lua]
local function SetTables()
local db, error = mysql.connect( “”, “”, “”, “” )

local DoorQuery = mysql.query( db, "SELECT * FROM doors" )

PrintTable( DoorQuery )

end
[/lua]

Here is the current loop I use for just grabbing EntID from a predefined table.
[lua]
local function SetAdminDoors()
for k, v in pairs( AdminDoors ) do
if Entity( v ):IsValid() then
Entity( v ):SetNWInt( “Type”, 3 )
Entity( v ):Fire( “lock”, “”, 0 )
Entity( v ):SetNWInt( “Locked”, 1 )
end
end
end
[/lua]

I’m not sure if this helps, but you can take from the table as [ 1 ][ 2 ] etc as fields… Sorry if it doesn’t; didn’t really understand your query.

Yea that would work but I am trying to automate the whole thing and I won’t know how many variables will be in the table. The query basically just returns EntID, Name, and Type.

Edit: The query returns a table, but I am not sure if it would be easier to have the types in different tables or to check the type during the for loop when setting the doors.

Edit: I came up with this, it seems to work, think I might ditch the names for doors though and just show admin doors as admin, public as public and closed as closed.
[lua]
local function SetTables()
local db, error = mysql.connect( “”, “”, “”, “” )

local DoorQuery = mysql.query( db, "SELECT * FROM doors" )

for k, v in pairs( DoorQuery ) do
	local DoorString = string.Explode( ":", tostring( v[1] .. ":" .. v[2] ) )
	
	if DoorString[2] == "3" then
		table.insert( AdminDoors, tonumber( DoorString[1] ) )
	elseif DoorString[2] == "1" then
		table.insert( ClosedDoors, tonumber( DoorString[1] ) )
	end
end

mysql.disconnect( db )

end
hook.Add( “InitPostEntity”, “SetTables”, SetTables )
[/lua]