mjr Posted May 14, 2012 Share Posted May 14, 2012 hi2all. the problem is that i don't know how to use table that is returned by dbPoll when query is success. function loginPlayerDB(localPlayer,name,pass) dbQuery( function(handle) local resultTable = dbPoll(handle,0) end, SQLconnect, "SELECT password FROM players WHERE name='"..name.."' LIMIT 1" ) end here, resultTable must have table with password that i need to use later, but i don't know how to manage this table. Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 https://forum.multitheftauto.com/viewtop ... 42b29ceffe Link to comment
mjr Posted May 14, 2012 Author Share Posted May 14, 2012 so comprehensive answer. THANK YOU! can someone else tell me how to get variable? Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 so comprehensive answer. THANK YOU! i gave you link. You not want read. Good luck. Link to comment
mjr Posted May 14, 2012 Author Share Posted May 14, 2012 i know how to use search and i read it before, there is NO answer on my question Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 function loginPlayerDB( pPlayer, sName, sPass ) local aResult = dbPoll( dbQuery( SQLconnect, "SELECT password FROM players WHERE name = '" .. sName .. "' LIMIT 1" ), - 1 ) if aResult and type( aResult ) == 'table' then local sPassword = aResult[ 1 ][ 'password' ] -- get password from table -- TODO end -- TODO end Link to comment
mjr Posted May 17, 2012 Author Share Posted May 17, 2012 haha, not closed. i will be grateful to you if you tell me how exactly result writes in table? i have another query: local count = dbPoll(dbQuery(SQLconnect, "SELECT COUNT(*) FROM players"),-1) which returns amount of rows in mysql table. In previous query with your help i somehow figure out how to get returned variable, but here idk what to do. edit: for i, v in ipairs(count) do outputChatBox (tostring(v)) end outputs weird thing to the chatbox: what does it mean? one table in another table? Link to comment
TAPL Posted May 17, 2012 Share Posted May 17, 2012 haha, not closed. i will be grateful to you if you tell me how exactly result writes in table?i have another query: local count = dbPoll(dbQuery(SQLconnect, "SELECT COUNT(*) FROM players"),-1) which returns amount of rows in mysql table. In previous query with your help i somehow figure out how to get returned variable, but here idk what to do. edit: for i, v in ipairs(count) do outputChatBox (tostring(v)) end outputs weird thing to the chatbox: what does it mean? one table in another table? Try this, not sure if it will work. local count = dbPoll(dbQuery(SQLconnect, "SELECT * FROM players"),-1) if count and type(count) == 'table' then outputChatBox(#count) end end Link to comment
TAPL Posted May 17, 2012 Share Posted May 17, 2012 chatbox outputs "1" what wrong in this? you have 1 row or you have more? lol Link to comment
mjr Posted May 17, 2012 Author Share Posted May 17, 2012 read previous messages, Kenix used "table[1]['password']" syntax to get result from query, that's why 1 is outputted Link to comment
TAPL Posted May 17, 2012 Share Posted May 17, 2012 Try local count = dbPoll(dbQuery(SQLconnect, "SELECT * FROM players"),-1) if count and type(count) == 'table' then outputChatBox(#count["id"]) end end Link to comment
Kenix Posted May 17, 2012 Share Posted May 17, 2012 (edited) local aQuery = dbPoll( dbQuery( SQLconnect, 'SELECT * FROM players' ), - 1 ) if aQuery and type( aQuery ) == 'table' then for sIndex, sValue in pairs( aQuery[ 1 ] ) do outputChatBox( tostring( sIndex ) .. ' = ' .. tostring( sValue ) ) end end Maybe you mean this? I not understand what you want. Or you mean this? function table.size( a ) if type( a ) ~= 'table' then return false end local n = 0 for _ in pairs( a ) do n = n + 1 end return n end local aQuery = dbPoll( dbQuery( SQLconnect, 'SELECT * FROM players' ), - 1 ) if aQuery and type( aQuery ) == 'table' then outputChatBox( table.size( aQuery[ 1 ] ) ) end Edited May 17, 2012 by Guest Link to comment
TAPL Posted May 17, 2012 Share Posted May 17, 2012 local cont = 0 local count = dbPoll(dbQuery(SQLconnect, "SELECT * FROM players"),-1) if count and type(count) == 'table' then for i, v in ipairs(count) do cont = cont +1 end outputChatBox(cont) end Link to comment
mjr Posted May 17, 2012 Author Share Posted May 17, 2012 YEES! Kenix, you are my saviour i didn't thought of using for "aQuery[ 1 ]" in loop! ps. chatbox outputted "COUNT(*)" as index variable, that's what i wanted to know when i started this topic. Tnaks to everyone! Link to comment
Kenix Posted May 17, 2012 Share Posted May 17, 2012 Hehe no problem. dbPoll return table like { { colname1 = value1, colname2 = value2, ... }; { colname1 = value3, colname2 = value4, ... }; ... } 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