tags:

views:

59

answers:

1

I have tried this in another post but trying my luck again. My current array that I am making produce a different result than I am wanting.

I want to have this kind of out put

Row: 0: Column: 1: ID 1  
Row: 1: Column: 1: ID 1 
Row: 0: Column: 2: ID 2   
Row: 1: Column: 2: ID 2   
Row: 2: Column: 2: ID 2   
Row: 3: Column: 2: ID 2  
Row: 0: Column: 3: ID 3  
Row: 1: Column: 3: ID 3  

As you can see the Rows and columns change based on the ID. So if the ID is same it just go to next row in the same column. However if id is changed it goes to next column and rows start.

Currently I my code looks like this

for($i=0;$i<count($pv->rawData); $i++) {   
 $relative=0; 
 $relativeTypeID = -1;  
 if ($pv->rawData[$i]->relativeTypeID != $relativeTypeID) {  
   $relativeTypeID = $pv->rawData[$i]->relativeTypeID;   
   $iTypeCount++;  
 }  
 if(!empty($pv->rawData[$i]->description)) {  
   $pv->results[$i][$iTypeCount][0] = $pv->rawData[$i]->description;  
   echo "Row: ".$i.": Column: ".$iTypeCount.": ID".$relativeTypeID." <br>";  
 }  
}  

It gives me the following output

Row: 0: Column: 1: ID1  
Row: 1: Column: 2: ID1  
Row: 2: Column: 3: ID2   
Row: 3: Column: 4: ID2  
Row: 4: Column: 5: ID2   
Row: 5: Column: 6: ID2   
Row: 6: Column: 7: ID2  
Row: 7: Column: 8: ID2   
Row: 8: Column: 9: ID2   
Row: 9: Column: 10: ID2  
Row: 10: Column: 11: ID2   
Row: 11: Column: 12: ID2   
Row: 12: Column: 13: ID2  
….  
….  

As you can see the Row and Columns are changing but not with ID number.

I appreciate your help

Thanks

A: 

I can't (won't) decipher that for loop you've thrown up there. If you could provide a var_dump() of your $pv->rawData array I could do something better, but in pseudo-code:

foreach($column as $i => $col) {
    foreach($col->row as $j => $thing) {
        echo "Row: $j: Column: $i: ID {$thing->id}\n";
    }
}
hobodave
thank you for your reply. here is var dump array 0 => object(stdClass)[17] public 'relativeTypeID' => string '1' (length=1) public 'relation' => string 'Mother' (length=6) public 'description' => string 'Anemia' (length=6) 1 => object(stdClass)[18] public 'relativeTypeID' => string '1' (length=1) public 'relation' => string 'Mother' (length=6) public 'description' => string 'Alcoholism' (length=10)
5 => object(stdClass)[22] public 'hiddenByUser' => string 'cccc' (length=27) public 'hiddenByClinic' => string 'ccc’ (length=26) public 'relativeTypeID' => string '2' (length=1) public 'relation' => string 'Father' (length=6) public 'description' => string 'HEADACHE ' (length=23) 6 => object(stdClass)[23] public 'relativeTypeID' => string '2' (length=1)) public 'relation' =>
string 'Father' (length=6) public 'description' => string ' 00142' (length=19) 7 => object(stdClass)[24] public 'relativeTypeID' => string '2' (length=1) public 'relation' => string 'Father' (length=6) public 'description' => string 'Alcoholism' (length=10) 8 => object(stdClass)[25] public 'relativeTypeID' => string '2' (length=1) public 'relation' => string 'Father' (length=6) public 'description' => string 'Alcoholism' (length=10)