[ciapug] Multi-dimensional array

Jerry Weida ciapug@cialug.org
Mon, 17 Nov 2003 11:34:43 -0600


Okay, let's say for example that your query returns all three of these 
results.  Here is a quick and dirty way to record them all.

$i = 0;    // just a place holder
while ( $rec = mysql_fetch_object($result)) {
      // do tests to confirm match
     $result_array[$i++] = $rec;
}

// At this point you have an array of objects.  This could just as 
easily be an array of arrays.
// Now you can simply do a count on the array

$num_records = count($result_array);
// or
$num_records = $i - 1;
echo "$num_records found";

Chris Hettinger wrote:

>As I loop through a result set I test each row, and for each row that passes, I need to record the information from 3 of the fields in the result set. Once I reach the end of my result set I need to look at the array of information, and count the number of records that had matched. Then I have a additional test I can run if I have more than one 1 row in my array. The goal is to find a 'single' match within a set of information that can in many cases have multiple results that can contain nearly exact information... Think, medical information where the only difference at times is the date on a policy, either it's active or not... or multiple policies for an individual...much of the information I have can be the same.
>
>To do this I believe I need to use a multi-dimensional array, but I am not sure how to go about implementing this. My knowledge of arrays is low, and the doc's I have read haven't cleared this up for me.
>
>For an example say the fields are
>1) SSN
>2) Birth date
>3) Date Joined
>
>So say I have 3 records pass my tests I need to record
>	
>ssn                dob              joined
>111-11-1111   1990-03-05    2003-01-01
>222-22-2222   1990-03-05    2001-03-07
>333-33-3333   1990-03-05    1987-12-23
>
>When I count the array, I need to know I have 3 records.
>
>What I am hoping for here, is a example of how to create this array, and how to properly index it so I can count the rows properly.
>
>
>
>-Chris Hettinger, Web Specialist
>-IFMC/ENCOMPASS
>-www.encompas.com
>-(515) 279-8730
>
>
>
>CONFIDENTIALITY NOTICE:  This communication, including any attachment, may contain confidential information and is intended only for the individual or entity to whom it is addressed.  Any review, dissemination, or copying of this communication by anyone other than the intended recipient is strictly prohibited.  If you are not the intended recipient, please contact the sender by reply email, delete and destroy all copies of the original message.'
>
>_______________________________________________
>ciapug mailing list
>ciapug@cialug.org
>http://cialug.org/mailman/listinfo/ciapug
>  
>