Jump to content

Show a table in outputchatbox


Austrothalik

Recommended Posts

i`m  having  some  difficult  do that,  right  now im haiving  this  error

ERROR: blips/blips.lua:60:  attempt to concatenate local 'v' (a table value)

what  im trying to do:

function listTable(queryHandle)
    local db  = dbConnect("sqlite","blips.db")
    local p = dbPoll(dbQuery(db, "SELECT id,icon,name FROM tabelaBlips"), -1);
    if (#p > 0) then
        for k,v in pairs(p) do
            outputChatBox(k.." = "..v);
        end
    end
end

addCommandHandler("listTable",listTable,false,false)

can sameone  help  me?

Link to comment
  • Discord Moderators

It's because you are trying to turn table 'v' into a string.

As you can find on the wiki for dbPoll, in your case 'p' will be like this

{
    { colname1=value1, colname2=value2, ... },
    { colname1=value3, colname2=value4, ... },
    ...
}

So you need to refer to the column name first

outputChatBox(k.." = "..v.id);

For your purpose, I suggest using inspect instead which converts a table to a readable string.

function listTable(queryHandle)
    local db  = dbConnect("sqlite","blips.db")
    local p = dbPoll(dbQuery(db, "SELECT id,icon,name FROM tabelaBlips"), -1);
    if (#p > 0) then
        outputChatBox(inspect(p))
    end
end
addCommandHandler("listTable",listTable,false,false)

 

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