Jump to content

[HELP] Fix my script (databases)


Ziemo

Recommended Posts

Posted

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)

 

Posted

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.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

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

Please do not PM me with scripting related question nor support, use the forums instead.

Posted (edited)

This new function doesn't work, but when I delete: 

iprint( "qh " .. qh ..", result: ".. result )

from the older code, error doesn't show up

EDIT: never mind it showed, I just missed it

Edited by Ziemo
  • Moderators
Posted

Concat with iprint like this:

iprint( "qh ", qh, ", result: ", result )

@Ziemo

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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