我运行了一个查询,该查询通过另一个数据库调用指定的ID来选择行,该数据库调用属于拖放菜单布局构建器。
我无法按字段获取订单才能正常工作。
我做错了还是我只是对MIDER理解了ORDER BY FIELD()sql查询。
这是查询:
$databasemenustring = '2,3,1,4';
$datamenu = $pdo->query("SELECT id, name, title, slug FROM pages WHERE id IN({$databasemenustring2}) AND islive=1 ORDER BY FIELD('id', {$databasemenustring})");
目前,它只是通过id desc订购。
谢谢 :)
最佳答案
Change ORDER BY FIELD('id',
至
ORDER BY FIELD(id,
这是一个示例,将字段名作为字符串文字传递时,它不会保留指定的顺序
mysql> select idfields from fields where idfields in (132,124,130,125) order by field('idfields',132,124,130,125);
+----------+
| idfields |
+----------+
| 124 |
| 125 |
| 130 |
| 132 |
+----------+
和
mysql> select idfields from fields where idfields in (132,124,130,125) order by field(idfields,132,124,130,125);
+----------+
| idfields |
+----------+
| 132 |
| 124 |
| 130 |
| 125 |
+----------+