【问题标题】:order by StudentId in query using cakephp使用 cakephp 在查询中按 StudentId 排序
【发布时间】:2020-12-31 07:16:12
【问题描述】:

您好,我正在尝试通过查询订购数据。 我检查了许多文档,但它们有 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);

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

【问题讨论】:

    标签: cakephp-2.0


    【解决方案1】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      相关资源
      最近更新 更多