• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved How to get multiples values from mysql tables?

viniciusturko

New Member
Joined
Jun 23, 2009
Messages
94
Reaction score
2
Location
Brasil
Hello,

I'm making a vip system that uses mysql tables to save some values. One of these values is the "vipdays". My doubt consists in how can I get the "id" of 'players' that have a number higher than 0 in their "vipdays" field?

When I try to get these values, the function returns just the first id that it founds and not all of them.
Does anybody know how to do it?

Note : 'vipdays' is a column located at 'players' table on database.
 
Are you sure it's not in the accounts table?

SQL:
SELECT id FROM accounts WHERE vipdays > 0 LIMIT 1;
This'll just break...
 
Last edited:
Yes I am.

I've just modified the players table to add the vipdays column.
Korrex, this query does not return the ids, it just selects. The problem is that I know how to make it return 1 id, and not all that it founds...

--

Still not working, it returns just the first found.
I'm using this function :

local res = db.getResult('SELECT id FROM players WHERE vipdays > 0 LIMIT 0')
ret = res:getDataInt("id")
print(ret)
 
Last edited:
remove the LIMIT X to get more results.. ("LIMIT 1" basically means "give me the first result only")
i've got no idea how getDataInt("id") treats multiple results though :/
 
Code:
local result = db.getResult('SELECT id FROM players WHERE vipdays > 0 LIMIT 0')
local tbl = {}
if (result:getID() ~= -1) then
   repeat
     table.insert(tbl, result:getDataInt("id"))
   until not result:next()
 print(result)
end
 
Lua:
function f()
	local result, tmp = db.getResult("SELECT id FROM players WHERE vipdays > 0 LIMIT 0;"), {}
	if (result:getID() ~= -1) then
		table.insert(tmp, result:getDataInt("id"))
	end
	return tmp
end
This function returns an array of characters, which satisfies the query.
 
Lua:
function f()
	local result, tmp = db.getResult("SELECT id FROM players WHERE vipdays > 0 LIMIT 0;"), {}
	if (result:getID() ~= -1) then
		table.insert(tmp, result:getDataInt("id"))
	end
	return tmp
end
This function returns an array of characters, which satisfies the query.

Thanks a lot, rep++
But even with this function, In my case, the best option is to use just the query to change the fields like :

Code:
db.executeQuery('UPDATE `players` SET  `vipdays` =  vipdays - 1 WHERE `vipdays` > 0')

Thanks everyone, problem solved.
 
Back
Top