Jump to content

MySQL Help


HereIsTheOne

Recommended Posts

Hello! I'm creating a character selector using MySQL and I have some troubles. I use this to get the account players:

local accData = singleQuery("SELECT * FROM players WHERE account=? LIMIT 3",string.lower(account))
		for i=3,1,-1
		do
			if(accData.username) then
				outputChatBox(accData.username,source,255,0,0, true) -- used to check results
			end
		end

I'm using simple MySQL functions, these is the singleQuery function:

function singleQuery(str,...)
	if (connection) then
		local query = dbQuery(connection,str,...)
		local result = dbPoll(query,-1)
		if (type(result == "table")) then
			return result[1]
		else
			return result
		end
	else
		return false
	end
end

It's normal that these function returns only one result. What I want is to list all of the results. If I have 4, i want to do a for loop with the 4 results. Anyone knows how I can modify this function to make another one called, for example, multipleQuery(str,..)?

I don't know if it's possible to do something like "accData[1]" for character 1, "accData[2]" for character 2, etc..

 

Thanks!

Link to comment
8 hours ago, HidroDF said:

I don't know if it's possible to do something like "accData[1]" for character 1, "accData[2]" for character 2, etc..

That is exactly what you ahve to do. The results are returned in an array like table. Every entry in that table is one row from your database.
Every row in that table is also a table, of which the keys are the string names of the columns in your database table.

 

if(accData[i].username) then
  outputChatBox(accData[i].username,source,255,0,0, true) -- used to check results
end

 

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