错误的参数#1到'ipairs'(表格预期,得到布尔值)

时间:2018-01-22 18:54:53

标签: mysql lua

控制台错误;

117: call: failed to call 'mysql:select' [string "?"]
117: bad argument #1 to 'ipairs' <table expected, got boolean>

功能;

function openAdvertisements( player, command )
    local advertisements = { } --These will hold our advertisements to send to the client and populate our advertisement tables.

    if not player then player = source end

    --Fetch all of the advertisements from the database
    for _, ad in ipairs( exports.mysql:select('advertisements') ) do
        if tonumber( ad.expiry ) >= tonumber( getRealTime().timestamp ) then --Check if the advertisement has expired, delete it if so.
            ad.author = exports.mysql:select_one( "characters", { id = ad.created_by } ).charactername
            table.insert( advertisements, ad )
        else
            deleteAdvertisement( ad.id )
        end
    end

    triggerClientEvent( player, resourceName .. ":display_all", root, advertisements, exports.integration:isPlayerAdmin( player ) ) --Send the advertisements to the client to create the GUI.
end

第117行; for _,ad in ipairs(exports.mysql:select('advertisements'))do leaveCs(CID)

1 个答案:

答案 0 :(得分:0)

当   exports.mysql:select('advertisements')返回boolean失败,您无法在ipairs上使用boolean,因为ipairs可以与表格一起使用。

为什么exports.mysql:select('advertisements')未能致电?

,因为 在表格周围加上引号,因为它们不是字符串 应该这样做

exports.mysql:select("SELECT * FROM 'advertisements' WHERE <something>")