Austrothalik Posted February 27, 2021 Share Posted February 27, 2021 how i can show information from my SQLite table with outputChatBox? i'm creating blips and storing them, then when i do /showBlips i want show a list of my SQL Table. How i can to this? maybe with arrays? how in MTA? Link to comment
Tekken Posted February 27, 2021 Share Posted February 27, 2021 local p = dbPoll(dbQuery(database, "SELECT * FROM `TableName`"), -1); if (#p > 0) then for k,v in pairs(p) do outputChatBox(k.." = "..v); end end That should do it Link to comment
Austrothalik Posted February 27, 2021 Author Share Posted February 27, 2021 9 hours ago, Tekken said: local p = dbPoll(dbQuery(database, "SELECT * FROM `TableName`"), -1); if (#p > 0) then for k,v in pairs(p) do outputChatBox(k.." = "..v); end end That should do it https://ibb.co/p08Pm7W o got this messages from the console when i start the resource Link to comment
Tekken Posted February 27, 2021 Share Posted February 27, 2021 Do you know how scripts work? Link to comment
Austrothalik Posted February 28, 2021 Author Share Posted February 28, 2021 17 hours ago, Tekken said: Do you know how scripts work? Im starting now. Can you help me ? Link to comment
Tekken Posted February 28, 2021 Share Posted February 28, 2021 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 Link to comment
Austrothalik Posted February 28, 2021 Author Share Posted February 28, 2021 33 minutes 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 Oh ir course hahaha i forget to put It on a functin, sorry Link to comment
Austrothalik Posted February 28, 2021 Author Share Posted February 28, 2021 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
Gordon_G Posted February 28, 2021 Share Posted February 28, 2021 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now