papa.ramu
papa.ramu

Reputation: 423

data retrieving not getting properly

if(isset($id)){


        $groups=$this->User->findByuser_group_id($id);
        $this->set('groups', $groups);

    }

This is code amn using to get database details from user by filtering user_group_id but here i am getting only only one value as per the user_group_id but in db am having morethen 5 users

Upvotes: 1

Views: 47

Answers (2)

AD7six
AD7six

Reputation: 66208

Call find

Magic finders are sometimes useful but if you avoid them you'll find your code is easier to read, and more obvious how to modify.

To get one record:

$one = $this->User->find('first', array(
    'conditions' => array(
        'user_group_id' => $id
    )
));

To get five records:

$many = $this->User->find('all', array(
    'conditions' => array(
        'user_group_id' => $id
    ),
    'limit' => 5
));

The find method is very flexible/versatile - check the docs for more ways to use it.

Upvotes: 0

Thulasi
Thulasi

Reputation: 116

$groups=$this->User->findAllByuser_group_id($id);
        $this->set('groups', $groups);

Change find to findAll

Upvotes: 3

Related Questions