dongluan1901 2017-04-25 06:35
浏览 543
已采纳

CI有没有办法查询自定义order_by

Is it possible to customize the order_by query in MySQL or in CI ? Such as I want my column to be ordered by ('1', '11', '4', '2', '21', '3', '5', '7') So if I query it as ASC the result will show in the order of my customized order.

If it is not possible, what is the best workaround to get these order ? Hoping for a simple solution just using the MySQL query.

All answers and suggestions are greatly welcomed. Thanks.

  • 写回答

2条回答 默认 最新

  • dongsimang4036 2017-04-25 06:42
    关注

    Try this one.

    $this -> db -> order_by('FIELD ( table.id, 1, 11, 4,2,21,3,5,7 )');
    

    link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?