I've got a a table with a column request_time. There will be multiple requests and I want to get the latest request of a particular username:

我有一个包含request_time列的表。将有多个请求,我想获得特定用户名的最新请求:

$this->Requests->find('all', 'conditions' => array (
                                               'username' => $username, 
                                               'MAX'=> 'request_time'));

The above doesn't work. Is there something in Cakephp or do I need to do my own ->query()?

以上不起作用。在Cakephp中有什么东西或者我需要自己做 - > query()吗?

2 个解决方案

#1


12

You can use the following:

您可以使用以下内容:

$this->Requests->find('first', array('conditions' => array('username' => $username), 
                               'order' => array('id' => 'DESC') ));

Where id is the auto incremented primary key. This will give you the latest (single) record, if you are using first in find method, or else use all instead.

其中id是自动递增的主键。如果您在find方法中首先使用,这将为您提供最新的(单个)记录,或者使用all。

If you are not using primary key, you can try the following:

如果您不使用主键,则可以尝试以下操作:

$this->Requests->find('first', array('conditions' => array('username' => $username), 
                               'order' => array('request_time' => 'DESC') ));

更多相关文章

  1. 在数据库设计中使用用户名作为主键是不是很糟糕?
  2. ubuntu下的Samba配置:使每个用户可以用自己的用户名和密码登录自

随机推荐

  1. ViewPager的定时滚动,动态加载数据
  2. android Uri获取真实路径转换成File的方
  3. Android如何在java代码中设置margin
  4. android 加边框
  5. android panellistview 圆角实现代码
  6. 关于android分辨率兼容(屏幕适配)问题
  7. Android Studio 开发依赖库集锦
  8. suse linux android sdk 下载.安装.配置
  9. Android(安卓)Q暗色模式适配踩坑—状态栏
  10. Android Content Provider详解及示例代码