我现在正在使用这个简单的查询:
SELECT * FROM ships ORDER BY shipid ASC
现在,我有一个应搜索的舰船阵列...
$shipid = array("1","9","19","73");
有没有一种方法可以轻松地执行无循环查询或构建查询字符串?
我正在寻找这样的东西:
SELECT * FROM ships WHERE shipid=(IS IN ARRAY shipids) ORDER BY shipid ASC
谢谢!
最佳答案
尝试使用php implode()
函数将数组转换为字符串,例如:
$ships = implode(",", ships);
并像这样使用它:
"SELECT * FROM ships WHERE shipid IN (".$ships.") ORDER BY shipid ASC"
关于mysql - MySQL查询数组值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44746009/