drruhc4944 2014-09-16 20:18
浏览 30

FuelPHP的ORM包未正确订购商品

I have a table with a 'title' field, I am trying to get all rows in this table, and order them by the title ASC. The four records I am testing with have the titles:

Another test

My New Page

NEW

aaa

This is also the order the rows are returned which is incorrect. 'aaa' should be at the top of the list. I assume the problem is with the lower and upper case characters.

I want to order by LOWER(title) rather then just title however I am having issues making this work in FuelPHP.

The code I'm using to select the records is:

$pages = Model_pages::find('all', array(
    'order_by' => array('title' => 'asc')
));

How do I make the code above order items regardless of their 'case'?

EDIT:

@Uru, thanks for the feedback :) I have tried the following code, all variations result in SQL or PHP errors:

$pages = Model_pages::find('all', array(
    'order_by' => \DB::expr('LOWER(title) ASC')
));

$pages = Model_pages::find('all', array(
    'order_by' => \DB::expr('LOWER(title)')
));

$pages = Model_pages::find('all', array(
    'order_by' => \DB::expr('LOWER(title) ASC')
));

$pages = Model_pages::find('all', array(
    'order_by' => array( \DB::expr('LOWER(title)') )
));

$pages = Model_pages::find('all', array(
    'order_by' => array( \DB::expr('LOWER(title) ASC') )
));

$pages = Model_pages::find('all', array(
    'order_by' => array( \DB::expr('LOWER(title)') => 'ASC' )
));
  • 写回答

2条回答 默认 最新

  • dousi6701 2014-09-17 13:46
    关注

    You should be able to use DB::expr('LOWER(title)') to escape expressions and use that instead of 'title'.

    If this does not work and there is nothing in the documentation then this feature is currently not supported.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害