【问题标题】:how to display max and min number from database in cakephp如何在cakephp中显示数据库中的最大值和最小值
【发布时间】:2015-03-26 00:27:08
【问题描述】:

如何在 cakephp 控制器部分显示最大和最小数字。

$rs = $this->Item->find('all' , array ('fields' => array('Max(Item.no) as no')));

我想要项目表的最大数量。

我需要在其中添加一些 rand 数字并将其保存在新行中。

【问题讨论】:

    标签: cakephp cakephp-2.0 cakephp-1.3 cakephp-2.1 cakephp-2.3


    【解决方案1】:

    使用下面的查询

    $rs = $this->Item->find('all' , array ('fields' => array('Max(Item.no) as no')));
    

    此查询将返回以下格式的最大数量

    Array
    (
        [0] => Array
            (
                [no] => 27
            )
    
    )
    
    $max = $rs[0]['no'];
    

    【讨论】:

    • 错误:未定义的索引:没有。如何解决这个问题
    • 尝试打印你的数组 pr($rs);这将显示结果。请确保调试设置为 2
    • 怎么样??我对这个蛋糕比较新鲜,你能解释一下吗。
    • 只需转到 app 文件夹 -> config 文件夹 -> core.php (打开此文件)现在搜索调试并像这样将零变为二 Configure::write('debug',2);
    • 注意(8):未定义索引:无[APP\Controller\ItemController.php,第28行];仍然显示错误
    猜你喜欢
    • 2021-01-27
    • 1970-01-01
    • 2019-09-20
    • 2012-01-19
    • 2021-08-18
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多