the following algorithm add users to a company array. I want to add a total of user for any given company. Howd I go about doing that
public function all_company_information($id = null){
$arrCompany = array();
$arrCompany['company']= array();
$arrData = array();
$this->autoRender = false;
$this->loadModel("User");
$users = $this->User->find('all');
foreach($users as $k => $user){
if(!in_array($user['User']['company_id'], $arrCompany['company'])){
$arrCompany['company'][$user['User']['company_id']][] = $user;
}else{
$arrCompany['company'][$user['User']['company_id']][] = $user;
}
}
}
Do a find on the Company model, then you can get a count of users easily.
Something along those lines. The returned results will be an array of
Companyrecords and eachCompanyrecord will have a list of associated user records in theUserkey.