Jump to content

Fetch data from MySQL


MURILLO

Recommended Posts

Hai, i trying to get all data from a single column, but he get only the first one everytime.I really don't know what to do anymore.

Spoiler

function getDataFromDB(data)
    local query = dbQuery(getConnection(), "SELECT * FROM stunts LIMIT 1")
    local result = dbPoll(query, -1)

    if (result and #result > 0) then
        for k, rows in ipairs(result) do
            return rows[data]
        end
    end
end

addEventHandler("onResourceStart", resourceRoot,
function()
	marker = createMarker(getDataFromDB("x"), getDataFromDB("y"), getDataFromDB("z"), "corona", 1.1, 255, 0, 0, 255)

    outputChatBox(getDataFromDB("name"))
end)

 


Pic from database:

4t4kwj6.png

Edited by MURILLO
Link to comment
addEventHandler("onResourceStart", resourceRoot,
    function()
        dbQuery(function(queryHandler)
            local results = dbPoll(queryHandler, 0)
             for k, row in ipairs(results) do
               marker = createMarker(row.x, row.y, row.z, "corona", 1.1, 255, 0, 0, 255)
             end
        end, getConnection(), "SELECT * FROM stunts LIMIT 1")
    end)

try this

  • Thanks 1
Link to comment
Just now, Dimos7 said:

addEventHandler("onResourceStart", resourceRoot,
    function()
        dbQuery(function(queryHandler)
            local results = dbPoll(queryHandler, 0)
             for k, row in ipairs(results) do
               marker = createMarker(row.x, row.y, row.z, "corona", 1.1, 255, 0, 0, 255)
             end
        end, getConnection(), "SELECT * FROM stunts LIMIT 1")
    end)

try this

It worked, thanks.

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