错误的参数#1到'ipairs'(期望表,布尔值) [英] bad argument #1 to 'ipairs' (table expected, got boolean)

查看:122
本文介绍了错误的参数#1到'ipairs'(期望表,布尔值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制台错误;

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中的广告(export.mysql:select('advertisements'))做 LeaveCs(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>") 

这篇关于错误的参数#1到'ipairs'(期望表,布尔值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆