mjr Posted May 14, 2012 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. i must learn not to be an asshole
Kenix Posted May 14, 2012 Posted May 14, 2012 https://forum.multitheftauto.com/viewtop ... 42b29ceffe http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
mjr Posted May 14, 2012 Author Posted May 14, 2012 so comprehensive answer. THANK YOU! can someone else tell me how to get variable? i must learn not to be an asshole
Kenix Posted May 14, 2012 Posted May 14, 2012 so comprehensive answer. THANK YOU! i gave you link. You not want read. Good luck. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
mjr Posted May 14, 2012 Author Posted May 14, 2012 i know how to use search and i read it before, there is NO answer on my question i must learn not to be an asshole
Kenix Posted May 14, 2012 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 http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
mjr Posted May 14, 2012 Author Posted May 14, 2012 Thanks topic may be closed i must learn not to be an asshole
Kenix Posted May 14, 2012 Posted May 14, 2012 No problem. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
mjr Posted May 17, 2012 Author 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? i must learn not to be an asshole
TAPL Posted May 17, 2012 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
mjr Posted May 17, 2012 Author Posted May 17, 2012 chatbox outputs "1" i must learn not to be an asshole
TAPL Posted May 17, 2012 Posted May 17, 2012 chatbox outputs "1" what wrong in this? you have 1 row or you have more? lol
mjr Posted May 17, 2012 Author Posted May 17, 2012 read previous messages, Kenix used "table[1]['password']" syntax to get result from query, that's why 1 is outputted i must learn not to be an asshole
TAPL Posted May 17, 2012 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
Kenix Posted May 17, 2012 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 http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
TAPL Posted May 17, 2012 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
mjr Posted May 17, 2012 Author 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! i must learn not to be an asshole
Kenix Posted May 17, 2012 Posted May 17, 2012 Hehe no problem. dbPoll return table like { { colname1 = value1, colname2 = value2, ... }; { colname1 = value3, colname2 = value4, ... }; ... } http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
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