gpt4 book ai didi

javascript - node-mysql 在查询中使用数组

转载 作者:行者123 更新时间:2023-11-29 04:44:52 25 4
gpt4 key购买 nike

我正在尝试使用数组进行查询,但出现解析错误。

a - 包含一个数组

例如:[ 7, 26, 87, 65, 86, 23, 63, 69, 44, 61, 8, 79, 47, 88, 15, 17 ]

conexao_bd.escape(a) - 转义数组

例如:7、26、87、65、86、23、63、69、44、61、8、79、47、88、15、17

它需要采用这种格式 (7, 26, 87, 65, 86, 23, 63, 69, 44, 61, 8, 79, 47, 88, 15, 17),所以我可以在查询。对如何更改格式有帮助吗?

代码

conexao_bd.query("SELECT question, answer FROM ", conexao_bd.escape(tipo) + " WHERE id IN " + conexao_bd.escape(a) ,function(err, rows){

if(err) console.log("Erro na query questions: "+err);
else{
perguntas.questions.push(rows);
console.log(JSON.stringify(perguntas));
}
});

最佳答案

查看 Array.join() 以将其作为字符串返回。这是一个基本的 javascript 问题,与 Node 无关。

关于javascript - node-mysql 在查询中使用数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20828406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com