0

I have the code below . it looks for the case and creates an array of rows and columns. $pv->results[$row1][1][0] actually is $pv->result->[rownumber][coulmnnumber][0]. Now this is for only 2 columns as you can see. However I want an array like $myArr = array(0=>1, 1=>7, 2=>8, 3=>9 ) to be added below for column. What it is doing, is adding 4 columns (0,1,2,3) into the code below. So now I will have 4 cases instead of 2 cases as I need to more columns. Also the case value will not be 1 and 2, it will be 1, 7, 8 and 9 respectively. How can I do that? Thanks.

for($i=0;$i<count($pv->rawData); $i++){ 
SWITCH ($pv->rawData[$i]->my ID){
         CASE '1':
          $row1++;
          $pv->results[$row1][1][0] =  $pv->rawData[$i]->data;

           break;

        CASE '2':
          $row2++;
         $pv->results[$row2][2][0] =  $pv->rawData[$i]->data;

          break;    
}       
8
  • @user295189: you can use backticks to delineate and format inline code, and indent lines with four spaces for multiline code. Click the orange question mark in the post editor toolbar for more formatting information. Also, your description of what you're trying to accomplish needs quite a bit of clarification. Try including sample input and output data. Commented May 6, 2010 at 4:45
  • Yeah, I didn't understand at all what you're after. $pv is an object instance of sorts, but the code above is not valid ($pv->rawData[$i]->my ID), nor do I understand what your cases are supposed to react to (ints, text, what?) As to the last question, case '1': ... break ;case '7': ... break ;case '8': ... break ;case '9': ... break ; Commented May 6, 2010 at 5:34
  • Wow, did we really have 3 simultaneous edits? Commented May 6, 2010 at 5:46
  • not sure how else I can explain this better but I will try. All I want is 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 again I will add the code in the comment below Commented May 6, 2010 at 6:07
  • for($i=0;$i<count($pv->rawData); $i++) { $relative=0; $relativeTypeID = -1; if ($pv->rawData[$i]->relativeTypeID != $relativeTypeID){ $relativeTypeID = $pv->rawData[$i]->relativeTypeID; $iTypeCount++; $iColumnHeaders[$iTypeCount] = $pv->rawData[$i]->relation; } Commented May 6, 2010 at 6:09

1 Answer 1

1

i think you're looking for this;

$idField = 'my ID';
foreach( $pv -> rawData as $data ) $pv -> results[ ++${ 'row' . $data -> $idField } ][ $data -> $idField ][ 0 ] = $data -> data;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.