• 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!

getDBPlayersCount() : -[

Status
Not open for further replies.

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
Lua:
function getDBPlayerCount()
    local Count = db.getResult("SELECT `id` FROM `players`;")
return table.maxn(Count)
end

function onSay(cid, words, param)
    local DB_BEFORE = table.maxn(db.getResult("SELECT `id` FROM `players`;").id)
    doPlayerSendCancel(cid, ""..DB_BEFORE.."")
end

:[ i need it to return me the number of players in database
 
Code:
function onSay(cid, words, param)
    return doPlayerSendCancel(cid, tostring(db.getResult("Select COUNT(id) from players;")))
end
 
Last edited:
Maybe this works
Lua:
function getPlayersCountInDB()

	query = db.executeQuery("select name from players")
	if(query ~= -1) then
		query:free()
		return #query:getDataString("name")
	end
	return LUA_ERROR
end
 
It may give wrong results if you delete players, because id field just returns auto increment state, not the real count.

Code:
function getDBPlayersCount()
    local result = db.getResult("SELECT COUNT(`id`) as `count` FROM `players` WHERE `deleted` = 0;")
    local tmp = result:getDataInt("count")

    result:free()
    return tmp
end
 
elf wins :D i used SELECT COUNT first, but i just needed another piece of code to get the number
thanks cykotitan and darkkhaos
i will use this to develop a necessary script to cleanup database
 
Status
Not open for further replies.
Back
Top