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

get count from sql?

Jgarder

Tprogramming Ex-Adm|n
Premium User
Joined
Jun 7, 2007
Messages
355
Reaction score
3
Location
Michigan
i cannot get this simple script to work.. all i want to do is count how many rows have the killer's id and return me an integer

PHP:
function onKill(cid, target)

	if (isPlayer(cid) == true) and (isPlayer(target) == true) and getPlayerStorageValue(cid,17100) ~= 1  then
		local id = getPlayerGUID(cid)
	local Info = db.getResult("SELECT `killer_id`,`killed_id` FROM `kill_log` WHERE `killer_id` = " .. id .. "")
	local Info2 = db.getResult("SELECT COUNT(1) as \"counter\" FROM `kill_log` WHERE `killer_id` = " .. id .. "")
	local counter = Info2:getDataInt("counters")
	doPlayerSendTextMessage(cid,22, "count of ".. info2 .."")
		if Info:getID() ~= LUA_ERROR then
			local killer_id, killed_id = Info:getDataString("killer_id"), Info:getDataString("killed_id")
			doPlayerSendTextMessage(cid,22, "gratz noob".. killer_id .."")
			Info:free()
			---
		local count = {}
		for i = 1, #killer_id do
				table.insert(count, 1)
		end
		if #count > 0 then
		doPlayerSendTextMessage(cid,22, "winnn ".. #count .."")
		end
	----
		end
end
	return TRUE
end
 
Code:
    local Info2 = db.getResult("SELECT COUNT([B][COLOR="Red"]1[/COLOR][/B]) as \"counter\" FROM `kill_log` WHERE `killer_id` = " .. id .. "")
    local counter = Info2:getDataInt("counter[B][COLOR="Red"]s[/COLOR][/B]")
fixed:
Code:
    local Info2 = db.getResult("SELECT COUNT(*) as counter FROM kill_log WHERE killer_id = " .. id)
    local counter = Info2:getDataInt('counter')

what is this i don't even
Code:
doPlayerSendTextMessage(cid,22, "count of ".. [B][U][COLOR="Red"]info2[/COLOR][/U][/B] .."")
 
Last edited:
(...)also what's the point of adding a semicolon at the end?

It's standard way to end query/statement :p

Also, no grave accents (`) around id

To escape table names and column names that clash with SQL keywords, enclose the name between two grave accent marks `` (ASCII value 96). If a column name must be escaped and is qualified as {tablename.column}, then the table and the column must be escaped individually as {`tablename`.`column`}. It is recommended that all table names and column names be escaped in this fashion to avoid clashes with reserved words and gain significant performance.
 
To escape table names and column names that clash with SQL keywords, enclose the name between two grave accent marks `` (ASCII value 96). If a column name must be escaped and is qualified as {tablename.column}, then the table and the column must be escaped individually as {`tablename`.`column`}. It is recommended that all table names and column names be escaped in this fashion to avoid clashes with reserved words and gain significant performance.
MySQL != MSSQL
 
Code:
    local Info2 = db.getResult("SELECT COUNT([B][COLOR="Red"]1[/COLOR][/B]) as \"counter\" FROM `kill_log` WHERE `killer_id` = " .. id .. "")
    local counter = Info2:getDataInt("counter[B][COLOR="Red"]s[/COLOR][/B]")
fixed:
Code:
    local Info2 = db.getResult("SELECT COUNT(*) as counter FROM kill_log WHERE killer_id = " .. id)
    local counter = Info2:getDataInt('counter')

what is this i don't even
Code:
doPlayerSendTextMessage(cid,22, "count of ".. [B][U][COLOR="Red"]info2[/COLOR][/U][/B] .."")

the script is just supposed to read from the kill log and count the kills the killer has

sorry about the script being so confusing.. it was 3am and i was going insane.. i have to test your changes but still,thanks a billion, im sure ill be posting more random clips of my scripts that wont work, you guys always helping us noobs? if you are that would be awesome.

EDIT--- script works great now, keeps count and doesnt have any errors.. thanks men..
 
Last edited:
Back
Top