我想在MeekroDB中编写这样的查询:
SELECT * FROM `tablename` WHERE `id` IN (3,1,2) ORDER BY FIELD (`id`,3,1,2)
我希望它能在meekro中像这样工作:
$possible_ids = array(1,2,3);
DB::query('SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids);
但它得到了这个:
SELECT * FROM `tablename` WHERE `id` IN (3,1,2) ORDER BY FIELD (`id`,(3,1,2))
有没有办法在这里避免这个括号?
答案 0 :(得分:1)
试试这个:
$possible_ids = implode(',', array(1, 2, 3));
//echo "SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids";
DB::query('SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids);
您还可以使用echo查询进行检查。 尝试工作正常。