'ipairs' 的错误参数 #1(需要表,得到布尔值)

2021-12-30 00:00:00 lua mysql

控制台错误;

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 行;对于 _, ipairs 中的广告(exports.mysql:select('advertisements')) 做离开Cs(cid)

line 117; for _, ad in ipairs( exports.mysql:select('advertisements') ) do leaveCs(cid)

推荐答案

何时exports.mysql:select('advertisements') 失败返回 boolean 并且你不能在 boolean 上使用 ipairs值,因为 ipairs 可以与表一起使用.

When exports.mysql:select('advertisements') failed return boolean and you can't use ipairs on boolean value because ipairs can use with tables.

为什么 exports.mysql:select('advertisements') 调用失败?

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

because put quotes around tables, for they are not strings and should do that like

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

相关文章