• For-Loop returns weird stuff
    8 replies, posted
Hello, I am trying to return a whole column from my table, but it returns weird stuff as soon as the for-loop comes. [CODE] queryNameTable = sql.Query("SELECT PlayerName FROM donations") --PrintTable(queryNameTable) for key, value in pairs(queryNameTable) do DListViewTest:AddLine(value) end [/CODE] output: table: 0x3401f4b8 table: 0x3401f760 table: 0x3401fa08 Can someone help? Thanks
Something tells me that you are trying to save a Lua table to a database.
No sir, I am trying to save a Lua table from a database and print its values out.
well what you are getting is what you would get if you to a tostring() on a table. So either you are trying to save/put a table into the database, which is incorrect, or you are incorrectly printing out the information retrieved from the database. I have a feeling DListViewTest:AddLine(value) might be calling tostring(() on the value.
I assume the 2nd one ( [I]or you are incorrectly printing out the information retrieved from the database. [/I]) However, I just want to loop through a table from the database and put all values into a DListView. [IMG]http://i.imgur.com/wk7wOob.png[/IMG] So I want the 1st row to look like... PlayerName Jok3r Dummy Do you have any idea how to code the above-mentioned?
sql.Query returns a table for each row. You need to select the key of each table that corresponds to the name of the column. So, if you want to get the PlayerName column for each row, do rowtable.PlayerName. Here's an example using your code. [code] queryNameTable = sql.Query("SELECT PlayerName FROM donations") --PrintTable(queryNameTable) for key, value in pairs(queryNameTable) do DListViewTest:AddLine(value.PlayerName) end [/code]
Thank you very much, I don't get "table:0x..." anymore. Now the next weird problem. I get values from the row I added 2-3 days ago.. (not the current values): This is my CURRENT database: [IMG]http://i.imgur.com/kXDgI5B.png[/IMG] This is my output in gmod: [IMG]http://i.imgur.com/FUMMqZC.png[/IMG] Code: [CODE] queryResultTable1 = sql.Query("SELECT PlayerName FROM spenden") --PrintTable(queryResultTable1) for k,v in pairs(queryResultTable1) do DonationList:AddLine(v.PlayerName) end end [/CODE]
It's easy, the values were never removed, they are still in your database. [editline]20th October 2015[/editline] Since you are running your code clientside, the SQL will read from cl.db file.
Since I am running the code clientside, SQL will read from cl.db.. Jesus. Thanks, helps alot =)!
Sorry, you need to Log In to post a reply to this thread.