UAEpro Posted February 24, 2012 Share Posted February 24, 2012 hello if i got a table contain 3 rows for example playername-----Money-----points UAEpro---------109999-----3124 SoildSnake-------2313-------23 etscfsd----------1234---------43 and i want to get all this value and put it into a gui window how i can get the values ? Link to comment
Castillo Posted February 24, 2012 Share Posted February 24, 2012 addCommandHandler("get", function () local result = mysql_query(handler, "SELECT * FROM some_table") if (result) then for index, data in ipairs(result) do outputChatBox(data.playername .." - ".. data.Money .." - ".. data.points) end mysql_free_result(result) end end ) Link to comment
UAEpro Posted February 24, 2012 Author Share Posted February 24, 2012 i tried that ... table expected, got userdata Link to comment
Kenix Posted February 24, 2012 Share Posted February 24, 2012 addCommandHandler( "get", function ( ) local result = mysql_query( handler, "SELECT * FROM some_table" ) if result then while true do local row = mysql_fetch_assoc( result ) if not row then break end outputChatBox( row.playername .." - ".. row.Money .." - ".. row.points) end mysql_free_result( result ) end end ) Link to comment
UAEpro Posted February 24, 2012 Author Share Posted February 24, 2012 (edited) works .. Thanks <3 Edited February 24, 2012 by Guest Link to comment
UAEpro Posted February 24, 2012 Author Share Posted February 24, 2012 edit if i want to insert the value into a table table.insert(_top,{row.name,row.Money.row.point}) row is a nil value Link to comment
Castillo Posted February 24, 2012 Share Posted February 24, 2012 My code would have worked with the new DB functions, I have never used Ryden's module. Edit: table.insert(_top,{row.name,row.Money,row.point}) -- You forgot a comma after row.Money. Link to comment
UAEpro Posted February 24, 2012 Author Share Posted February 24, 2012 oh my mistake [lua] _top= {} function() table.insert(_top,{row.name,row.Money,row.point}) end insert is a nil Link to comment
Kenix Posted February 24, 2012 Share Posted February 24, 2012 addCommandHandler( "get", function ( ) local result = mysql_query( handler, "SELECT * FROM some_table" ) if result then local t = { } while true do local row = mysql_fetch_assoc( result ) if not row then break end table.insert( t, { name = row.playername; money = row.Money; points = row.points; } ) end -- example ------------------------------------------------------------------------ for i = 1,#t do outputChatBox( t[i]['name'] .." - ".. t[i]['money'] .." - ".. t[i]['points'] ) end -------------------------------------------------------------------------------------- mysql_free_result( result ) end end ) You can everything with this table. table.sort, ... Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now