sql.Query : How to get fields from table and convert them to strings...
5 replies, posted
So recently I just decided to jump into making this "simple" addon for pretty much any server.
It started out with me making a simple DFrame with a close button and a DLabel to create a box that had text from the code. I showed it to a coding buddy, and he said it was a cool idea and I should work on it by networking it to a table or something.
So after like 2 days I finally got a part of the script where it uploads a table to the database
Now I made the Table like this
CREATE TABLE `NAME` (
`Command` varchar ( 255 ),
`Name_Main` varchar ( 255 ),
`Name` varchar ( 65533 )
So after I did that I flipped out and got hyped that I got it working like that *still some issues about how it wont create a row in the table if there is too many characters but its fine so far.*
Now my next goal for this addon is to get a part of my script to get a field (Command) and fill a DComboBox Choices with the fields in the Command feild
Sort of how this code
local MAINMENU_COMMAND = vgui.Create("DComboBox", MAINMENU)
MAINMENU_COMMAND:SetValue( "NAME" )
for k, v in pairs( player.GetAll() ) do
MAINMENU_COMMAND:AddChoice( v:Name() )
But instead I want it to output the field Commands on the DComboBox Choices... Please help. If you need me to send more code or need more context just reply and I will try my best to provide. Thanks in advanced for help.
Convert your table into JSON and store it as JSON; util.TableToJSON to get it back. 255 chars may be too little for it.
sql.Query returns the info as a table of rows, reach row will have each column filled in with the corresponding column from your query. Assuming you're storing the information server side you'll have to network it using the net library.
Well yes, I am attempting to store it server side, but my main question was how would I make make it return the rows or only a column. I am a terribly "dev" and have now idea how to do it... thats why I had that little backstory because I justed jumped into this with no info. Gmod wiki wasn't really telling me how... I was really just hoping for some example code to help me out tbh
Can you give me an example code if you can?
SQL WHERE Clause
So I figured it out and in case anyone who doesn't know how to do it or wants to figure it out... here it is
*overcomplicated of course because I don't know how to make a simpler*
rv = net.ReadTable()
*inside some function or whatever you want*
local NAME = vgui.Create("DComboBox", MENU)
NAME :SetPos(5, 25)
NAME :SetValue( "Easy Rules" )
for k, v in pairs( rv ) do
for l, d in pairs( v ) do
NAME:AddChoice( d )
net.Receive("RETRIEVE_VALUES", function( len, ply)
local cv = sql.Query("SELECT (COLUMN) FROM (TABLE)")
net.WriteTable( cv )
Sorry, you need to Log In to post a reply to this thread.