2017-04-23 7 views
-1

コントローラから多次元配列をcodeigniterで表示するにはどうすればいいですか? コントローラに出力されていますが、表示するにはエラーが発生します。 私の配列結果:codeigniterの多次元配列にアクセスする方法

Array ( 
[0] => Array ([PcountID] => 1 [PcountNAME] => Abayas [Pcount] => 8 [ScountID] => 1 [ScountNAME] => Abayas [Scount] => 9) 
[1] => Array ([PcountID] => 3 [PcountNAME] => Hytaf [Pcount] => 16 [ScountID] => 3 [ScountNAME] => Hytaf [Scount] => 13) 
[2] => Array ([PcountID] => 5 [PcountNAME] => Rida [Pcount] => 2 [ScountID] => 6 [ScountNAME] => sss [Scount] => 3) 
[3] => Array ([PcountID] => 6 [PcountNAME] => sss [Pcount] => 7) 
) 

私のコントローラのコード:ビューで配列結果のこのタイプにアクセスする方法

for($i = 0 ; $i<$CinventoryP; $i++) 
{ 
for($j = 0; $j<$CinventoryPR; $j++) 
{ 
    if($inventoryP[$i]['product_id'] == $inventoryPR[$j]['product_id']) 
    { 
     $jj = $j; 
     $flag = 1; 
     break; 
    } 
    else{ 
     $flag=0; 
     $jj = $j;   
    } 

} 

if($flag==1) 
{  
    $outs[$i]['PcountID'] = $inventoryP[$i]['product_id']; 
    $outs[$i]['PcountNAME'] = $inventoryP[$i]['product_name']; 

    $outs[$i]['Pcount'] = $inventoryP[$i]['purchase_count'] - $inventoryPR[$jj]['purchase_returns_count']; 

} 
else{ 

    $outs[$i]['PcountID'] = $inventoryP[$i]['product_id']; 
    $outs[$i]['PcountNAME'] = $inventoryP[$i]['product_name']; 

    $outs[$i]['Pcount'] = $inventoryP[$i]['purchase_count']."<br>"; 
} 

} 

$this->load->view('inventory/view_inventory_report',$out); 

。助けてください。コントローラファイルで

答えて

0

あなただけのビューファイルにその後

$data['result'] = Array ( 
    [0] => Array ([PcountID] => 1 [PcountNAME] => Abayas [Pcount] => 8 [ScountID] => 1 [ScountNAME] => Abayas [Scount] => 9) 
    [1] => Array ([PcountID] => 3 [PcountNAME] => Hytaf [Pcount] => 16 [ScountID] => 3 [ScountNAME] => Hytaf [Scount] => 13) 
    [2] => Array ([PcountID] => 5 [PcountNAME] => Rida [Pcount] => 2 [ScountID] => 6 [ScountNAME] => sss [Scount] => 3) 
    [3] => Array ([PcountID] => 6 [PcountNAME] => sss [Pcount] => 7) 
    ) 

    $this->load->view('view_file_name',$data); 

を使用する必要が

$result variable will give all array 
print_r($result);