Snow-Man Posted March 1, 2017 Share Posted March 1, 2017 how to get all data from sql, in my script it's show me only recent data function getTransactionBankLog(player) if (player) then local transaction = exports.USCsql:query( "SELECT * FROM bank_transaction WHERE accName = ?", getAccountName(getPlayerAccount(player))) if transaction and transaction['log'] and transaction['date'] then local tran, date = transaction['log'] ,transaction['date'] return tran, date else return false end end end Link to comment
Moderators Citizen Posted March 1, 2017 Moderators Share Posted March 1, 2017 Assuming exports.USCsql:query can return an array of rows when appropriate, this should work: function getTransactionBankLog(player) local transactions = {} -- create a list if player then local results = exports.USCsql:query( "SELECT * FROM bank_transaction WHERE accName = ?", getAccountName(getPlayerAccount(player))) if results then for transaction, i in ipairs(transactions) do -- loop the results if transaction and transaction['log'] and transaction['date'] then table.insert(transactions, {tran = transaction['log'], date = transaction['date']}) -- filling the list from each result end end end end return transactions -- return the list end You should be able to use it like this: local transactions = getTransactionBankLog(somePlayerElement) for transaction, i in ipairs(transactions) do outputChatBox("#"..i.." -> tran: "..tostring(transaction.tran)..", date: "..tostring(transaction.date)) end Link to comment
Snow-Man Posted April 13, 2017 Author Share Posted April 13, 2017 i have tried your code and i got result -> table:2482C1F8 my code is works good but i only get one data 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