Jump to content

[HELP] Fix my script (databases)


Ziemo

Recommended Posts

Hi, I've started writing scripts connected to the database, and I struggle why the current script that I am working on doesn't work.

Info:

- Name of the table: accounts

- Columns: username, skin, money

- No errors

Here is my script:

function showStats(player)
    local playerName = getPlayerName(player)
    local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName)
    local result = dbPoll(qh, -1)
    if result then
        for _, row in ipairs(result) do
            outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "")
        end
    end
end
addCommandHandler("stats", showStats)

 

Link to comment

Do a test with this code:

function showStats(player)
    local playerName = getPlayerName(player)
    local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName)
    local result = dbPoll(qh, -1)
    if result then
        for _, row in ipairs(result) do
            outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "")
        end
    end
	iprint( "qh " .. qh ..", result: ".. result )
end
addCommandHandler("stats", showStats)

Also, post the code where you create the table and save these values if possible.

  • Thanks 1
Link to comment

Try:

function showStats(player)
    local playerName = getPlayerName(player)
    local qh = dbQuery(db, "SELECT skin, money FROM accounts WHERE username=?", playerName)
    local result = dbPoll(qh, -1)
    if result then
    	result = result[1]
        for _, row in ipairs(result) do
            outputChatBox("Skin: " ..row["skin"].. "Money: "..row["money"] .. "")
        end
    end
end
addCommandHandler("stats", showStats)

@Ziemo

  • Thanks 1
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...