【问题标题】:One particular id at first and after all ids in desc order首先是一个特定的 id,然后是 desc 顺序的所有 id
【发布时间】:2020-09-10 07:29:26
【问题描述】:

我首先需要获取一个特定的 id,然后,所有 id 都按降序排列。这就是我所做的,但是当我取消注释该订单行时,它将不起作用,

$result = $this->Practicetestanswers->find('all',
    ['contain' => ['Practicetestquestions' =>
        ['Practicetestconceptassignment' => ['Practicetestconcept', 'Practicetest']
        ]]])
    ->where(['Practicetestanswers.user_id' => $student_id,
        'Practicetestquestions.is_active' => 'y',
        'Practicetest.is_active' => 'y'
    ])
    ->select([
        'id' => 'Practicetest.id',
        'test_code' => 'Practicetest.test_code',
        'test_title' => 'Practicetest.test_title',
        'time_taken' => 'SUM(Practicetestanswers.time_taken)',
    ])
    ->group('Practicetest.id')
  //    ->order(["FIELD(Practicetest.id, '228')" => 'DESC'])   //need like this
        ->order(["Practicetest.id" => 'DESC'])
        ->hydrate(false)
        ->toArray();

【问题讨论】:

    标签: php mysql cakephp-3.0


    【解决方案1】:

    只需按条件将此行替换为您的订单

    ->order(['FIELD(Practicetest.id, "228")'=> 'DESC', "Practicetest.id" => 'DESC' ])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-15
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      相关资源
      最近更新 更多