使用 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).')',)));