使用 cakephp 在查询中按 StudentId 排序

问题描述

您好,我正在尝试通过查询对数据进行排序。 我检查了许多文档,但他们有 DESC 和 ASC。 我想通过我决定的号码订购。


    $bb = $this->StudentsTest->find('first',array('conditions' => array('StudentsTest.custom_test_title' => $customTestId,'StudentsTest.test_id' => null,'StudentsTest.student_id'  => array_values($result)),'order' => array('StudentsTest.student_id' =>  array_values($result))));

     print_r($bb);
     exit();

array_values($result) = (40,35,47,25,55,30);

但他们通过增加数字给我输出。请帮我解决这个问题。

解决方法

试试这个

$this->set('studentTests',$this->StudentsTest->find('all',array('conditions' => array('StudentsTest.custom_test_title' => $customTestId,'StudentsTest.test_id' => null,'StudentsTest.student_id'  => $result),'order' => 'FIELD(StudentsTest.student_id,'.implode(',',$result).')',)));

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...