Jump to content

[HELP] dbPoll


Azaroth

Recommended Posts

Hello.

I used dbPoll to get checkpoint model from database, but it works only to line: 7. Tried with outputChatBox(posX).

local ColSphere = getElementsByType ( "colshape" ) 
    for theKey,Sphere in ipairs(ColSphere) do 
        if isElementWithinColShape ( source, Sphere ) then 
            local posX, posY, posZ =  getElementPosition ( Sphere ) 
            local query = dbQuery( connection, "SELECT * FROM pickups WHERE posX="..posX ) 
            local result, numrows, errmsg = dbPoll ( query, -1 )     
            if numrows > 0 then 
                for result, row in pairs ( result ) do 
                    for column, value in pairs ( row ) do 
                    end 
                    outputChatBox(row["model"]) 
                end 
            end 
        end 
    end 

Link to comment

That means that you are not admin and have no right for this command. But anyway debugscript won't help you because your code is not client-side. I suppose you can't get a result in your function because of connection value returns false. In order to open a query to database you have to start a connection with it.

Link to comment

Oh... My first post is wrong... Was thinking about something else and wrote bad post. I want to get positions to teleport from database.

function Enter() 
    local ColSphere = getElementsByType ( "colshape" ) 
    for i, Sphere in ipairs(ColSphere) do 
            local positionX, positionY, positionZ =  getElementPosition ( Sphere ) 
            tempSphere = createColSphere ( positionX, positionY, positionZ, 2 ) 
            if  isElementWithinColShape ( source, tempSphere ) then 
            local query = dbQuery( connection, "SELECT * FROM pickups WHERE posX="..tostring(positionX) ) 
            local result, numrows, errmsg = dbPoll ( query, -1 ) 
                 
            for result, row in pairs ( result ) do 
                setElementPosition(source, row["posX"], row["posY"], row["posZ"]) 
                outputChatBox(row["posX"]) 
            end 
        end 
    end 
end 
  
addEvent( "Enterb", true ) 
addEventHandler( "Enterb", getRootElement(), Enter) 

Link to comment

strange code...

What is source? And why u warp source many times?

What this code should do?

also, result array should be parse with ipairs()

for i, row in ipairs ( result ) do 
    setElementPosition(source, row["posX"], row["posY"], row["posZ"]) 
    outputChatBox(row["posX"]) 
end 

Link to comment

I think that there is a problem with Query, because when I write another Query then it works.

local query = dbQuery(connection, "SELECT * FROM `pickups` WHERE `UID`=40" 

Works.

local query = dbQuery(connection, "SELECT * FROM `pickups` WHERE `posX`=?", tostring(positionX)) 

Didn't work...

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