epicrecipe Posted July 13, 2006 Posted July 13, 2006 I use FX.php, FM7, FMS7A, PHP 5.1.2 running on IIS. How can I use PHP to extract a found count for unique values from single column? Here is a mythical record set. larry, banana johnny, apple sally, banana bobby, pear billy, mango I'd like to find the number of unique fruits (4). One option is to order the record set and then run looping logic to disregard duplicates. This seems inefficient. How might I accomplish this using FX.php? Any ideas on using arrays / associative arrays? Thank you, Shannon
andygaunt Posted July 13, 2006 Posted July 13, 2006 You may want to look at some of the array functions at www.php.net 1 that springs to mind is array_count_values() Details of the function can be found at php.net
epicrecipe Posted July 17, 2006 Author Posted July 17, 2006 Thanks Andy. That is probably the final step in the process. I first need to figure out how to get all the values of a column of multiple records into a single array. I've found basic examples all over the net, but haven't figured out how to do it with an array returned via FX.php. I think my answer is somewhere in the realm of Associative arrays. (?) Any other ideas? I'll post my solution if I can figure it out. Shannon -=-=-
epicrecipe Posted July 17, 2006 Author Posted July 17, 2006 I figured it out. I'll continue my people/fruit example: <? $Search = new FX($serverIP,$webCompanionPort); $Search->SetDBData('FMPFile.fp7','LayoutName'); $Search->SetDBPassword($webPW,$webUN); $Search->AddDBParam('Fruit',' * '); $SearchResult=$Search->FMFind(); $FoundCount = $SearchResult['foundCount']; ?> This would return my mythical record set. larry, banana johnny, apple sally, banana bobby, pear billy, mango I studied the result of print_r($SearchResult); to learn how FX.php delivers XML produced by FileMaker. From there, I used a loop to build a new array. The new array is built on a single 'column' from the $SearchResult array. <? foreach($SearchResult['data'] as $SearchKey=>$SearchRecord) { $FruitArray[] = $SearchRecord['Fruit'][0]; } ?> Now I can pimp out my new array as needed... $FruitArray; would result: Array ( [0] => banana [1] => apple [2] => banana [3] => pear [4] => mango ) $FruitUnique = array_unique($FruitArray); would result: Array ( [0] => banana [1] => apple [2] => pear [3] => mango ) $ValuesPerFruit = array_count_values($FruitArray); would result: Array ( [banana] => 2 [apple] => 1 [pear] => 1 [mango] => 1 ) $FruitCount = count($FruitUnique); would result: 4 etc... HTH, Shannon -=-=-
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now