Friday, April 22, 2022

[FIXED] how to display max and min number from database in cakephp

Issue

how to display max and min number in cakephp controller part .

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

I want max number of Item table .

I need to add some rand number to that and save it in new row .


Solution

Use below query

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

This query will return max number in below format

Array
(
    [0] => Array
        (
            [no] => 27
        )

)

$max = $rs[0]['no'];


Answered By - shimar
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.