Jump to content

full sql info


Snow-Man

Recommended Posts

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

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
  • 1 month later...
  • 4 weeks later...

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