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

Lua Get more than 1 result at database with tfs 1.2

Antharaz

New Member
Joined
Jan 28, 2010
Messages
27
Reaction score
0
Hey guys,

I'm with a little problem....


I'm using TFS 1.2 and i don't know how can i get more than 1 result at a database...

In TFS 0.3.6 i can do it like this:

Lua:
local result = db.getResult("SELECT * FROM `tasks` WHERE `player_name` = '" .. player:getName() .. "' AND `status` = 'aberto'")
if result:getID() ~= -1 then
    repeat
        --here comes your code
    until not result:next()
end


But at TFS 1.2 it doesn't work... i tried like this:

Code:
function onSay(player, words, param)
    local player = Player(player)
    local r = db.storeQuery("SELECT * FROM `tasks` WHERE `player_name` = '" .. player:getName() .. "' AND `status` = 'aberto'")
    repeat
        player:sendTextMessage(2,result.getDataString(r, 'task'))
        --here comes your code
    until not result:next()
    return false
end


But it only return one of the tasks... can anyone help me?
 
Solution
E
something similar to this:
Lua:
function onSay(player, words, param)
    local orderQuery = db.storeQuery("SELECT * FROM `tasks` WHERE `player_name` = '" .. player:getName() .. "' AND `status` = 'aberto'")
    -- Detect if we got any results
    if orderQuery ~= false then
        repeat
            local task1 = result.getString(orderQuery, 'task')
            --here comes your code
        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end
stolen from znote shop code
something similar to this:
Lua:
function onSay(player, words, param)
    local orderQuery = db.storeQuery("SELECT * FROM `tasks` WHERE `player_name` = '" .. player:getName() .. "' AND `status` = 'aberto'")
    -- Detect if we got any results
    if orderQuery ~= false then
        repeat
            local task1 = result.getString(orderQuery, 'task')
            --here comes your code
        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end
stolen from znote shop code
 
Solution
something similar to this:
Lua:
function onSay(player, words, param)
    local orderQuery = db.storeQuery("SELECT * FROM `tasks` WHERE `player_name` = '" .. player:getName() .. "' AND `status` = 'aberto'")
    -- Detect if we got any results
    if orderQuery ~= false then
        repeat
            local task1 = result.getString(orderQuery, 'task')
            --here comes your code
        until not result.next(orderQuery)
        result.free(orderQuery)
    end
    return true
end
stolen from znote shop code

TY so much <3
 
Back
Top