【问题标题】:bad argument #1 to 'ipairs' (table expected, got boolean)'ipairs' 的错误参数 #1(预期的表,得到布尔值)
【发布时间】:2018-07-01 11:44:53
【问题描述】:

控制台错误;

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)

【问题讨论】:

  • 我通过将exports.mysql:select('advertisements') 更改为mysql:query("SELECT * FROM 'advertisements' WHERE 1") 解决了第二个问题,第一个控制台错误已更改为117: bad argument #1 to 'ipairs' &lt;table expected, got number&gt;

标签: mysql lua


【解决方案1】:

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

为什么exports.mysql:select('advertisements') 打电话失败?

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

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

【讨论】:

  • 我通过将exports.mysql:select('advertisements') 更改为mysql:query("SELECT * FROM 'advertisements' WHERE 1") 解决了第二个问题,第一个控制台错误已更改为117: bad argument #1 to 'ipairs' &lt;table expected, got number&gt;
  • 执行 print(exports.mysql:select("SELECT * FROM 'advertisements' WHERE 1")) 并说出你所看到的
  • 控制台输出:假
  • exports.mysql:select("SELECT * FROM 'advertisements' WHERE ") 这里有问题。我需要知道 mysql 和导出的类型,但是在这里使用 select 然后查询时可以说什么可能是错误的
猜你喜欢
  • 2020-12-22
  • 2023-01-04
  • 2020-05-19
  • 1970-01-01
  • 2017-04-08
  • 2021-07-29
  • 2021-08-22
  • 2019-08-28
  • 1970-01-01
相关资源
最近更新 更多