0

In the following cakephp mysql query, how do I find number of rows grouped each time?

$groupBy = 'PropertyViewer.ip_address';
$this->paginate = array(
  "group" => array( $groupBy ),
  "order" => array( "PropertyViewer.id desc" ) );
$view_info = $this->paginate( 'PropertyViewer', $conditions );
$this->set( 'view_info', $view_info );`

1 Answer 1

1

You can do it like in the following way, however I did not try it but it will work.

$groupBy = 'PropertyViewer.ip_address'; 
$this->paginate = array( "fields" => (..., 'COUNT(PropertyViewer.id) AS total_rows),
                         "group" => array( $groupBy ),
                         "order" => array( "PropertyViewer.id desc" ) );
$view_info = $this->paginate( 'PropertyViewer', $conditions );
$this->set( 'view_info', $view_info );`

Or you can also create a virtual Field in your model, if you need it to use frequently.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.