Jump to content

show a SQL View or table in outputChatBox


Austrothalik

Recommended Posts

1 hour ago, Tekken said:

How about you start by learning how to define a function and how you execute the function with addCommandHandler?

https://wiki.multitheftauto.com/wiki/AddCommandHandler

function listTable()
    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)

im doing  this  and  i recive  this message  when  i exec  the  command

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

 

Link to comment

A dbPoll return a value like this :

{
    
   { ["col_name1"] = value, ["col_name2"] = value }, -- row 1
   { ["col_name1"] = value, ["col_name2"] = value }, -- row 2


}

Etcetera...

 

So in your example, <v> variable is something like

{ ["col_name1"] = value, ["col_name2"] = value }, -- row 1

So you may need a second for loop to index the columns and their values in this <v> row

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