Jump to content

dbPoll's returned table


mjr

Recommended Posts

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. :roll:

Link to comment
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

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: c0069080fe2d.png what does it mean? one table in another table?

Link to comment
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: c0069080fe2d.png 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
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 by Guest
Link to comment
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...