Jump to content

dbPoll


GTX

Recommended Posts

Okay, nevermind for that.

The code below returns this error: attempt to get length of a userdata value. Why?

function updateRank() 
    for i, v in ipairs(getElementsByType("player")) do 
        if getElementData(v, "guest_") ~= 1 then 
            local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
            if res then 
                local result = mysql_fetch_assoc(res) 
                local rank = #sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                if rank then 
                    setElementData(v, "Rank", rank) 
                end 
            end 
        end 
    end 
end 

Link to comment
Okay, nevermind for that.

The code below returns this error: attempt to get length of a userdata value. Why?

function updateRank() 
    for i, v in ipairs(getElementsByType("player")) do 
        if getElementData(v, "guest_") ~= 1 then 
            local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
            if res then 
                local result = mysql_fetch_assoc(res) 
                local rank = #sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                if rank then 
                    setElementData(v, "Rank", rank) 
                end 
            end 
        end 
    end 
end 

"sqlC:query" is returning userdata, you can't get length of it. Use "mysql_fetch_assoc" and get length of it.

Link to comment
    function updateRank() 
        for i, v in ipairs(getElementsByType("player")) do 
            if getElementData(v, "guest_") ~= 1 then 
                local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
                if res then 
                    local result = mysql_fetch_assoc(res) 
                    local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                    local r = #mysql_fetch_assoc(rank) 
                    if r then 
                        setElementData(v, "Rank", r) 
                    end 
                end 
            end 
        end 
    end 

That? It shows 0 for me.

Link to comment
    function updateRank() 
        for i, v in ipairs(getElementsByType("player")) do 
            if getElementData(v, "guest_") ~= 1 then 
                local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
                if res then 
                    local result = mysql_fetch_assoc(res) 
                    local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                    local r = #mysql_fetch_assoc(rank) 
                    if r then 
                        setElementData(v, "Rank", r) 
                    end 
                end 
            end 
        end 
    end 

That? It shows 0 for me.

I don't know right cuz I don't use MySQL from much time but should not: "result["points"]" be "result[1].points" or "result[1]['points']"?

Link to comment
function updateRank() 
            for i, v in ipairs(getElementsByType("player")) do 
                if getElementData(v, "guest_") ~= 1 then 
                    local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
                    if res then 
                        local result = mysql_fetch_assoc(res) 
                        local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                        local r = mysql_fetch_assoc(rank) 
                        if r then 
                            setElementData(v, "Rank", r["points"]) 
                        end 
                    end 
                end 
            end 
        end 
  

Link to comment
function updateRank() 
            for i, v in ipairs(getElementsByType("player")) do 
                if getElementData(v, "guest_") ~= 1 then 
                    local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") 
                    if res then 
                        local result = mysql_fetch_assoc(res) 
                        local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") 
                        local r = mysql_fetch_assoc(rank) 
                        if r then 
                            setElementData(v, "Rank", r["points"]) 
                        end 
                    end 
                end 
            end 
        end 
  

This gets my points, and I want to make a "top list".

Example:

a = 100 points

b = 101 points

Element data:

b = 1

a = 2

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