note 104655 deleted from function.count by danbrown

From: Date: Wed, 29 Jun 2011 15:39:08 +0000
Subject: note 104655 deleted from function.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-181058@lists.php.net to get a copy of this message
Note Submitter: milespickens+php at gmail dot com ---- Here is a great way the count() function has helped me.. Here, I'm using PDO to return all rows to an array and I need to count how many patients are under each Doctor and I also need to keep the counts under the Doctor's Medical Groups... <?php //This is code that I have in a function which queries referred //patients, the Doctor who referred them and the Medical //Group to which the Doctor belongs.... //the results are put into an array called $patarray['results'] $patarray['results'] = $result->fetchAll(); //now I loop through the results array using the Medical Group // and the Doctor name for the Array Keys foreach($patarray['results'] as $row){ $curgroup = $row['MedicalGroup']; $curdoc = $row['RefMD']; $patarray[$curgroup][$curdoc][] = true; } return $patarray; ?> Ok, now I'll look at that Key to get the patient count for each Doctor. <?php //You'll need to call your function, I'll keep the name //"$patarray" to avoid confusion. foreach($patarray['results'] as $row){ $mdgrp = $row['MedicalGroup']; $rfmd = $row['RefMD']; $num = count($patarray[$mdgrp][$rfmd]); echo 'Doctor: '.$rfmd.' Referred '.$num.' patients.'; } ?> The result will look something like 'Doctor: Doe, John Referred 34 patients.'

« previous php.notes (#181058) next »