2017-04-23 96 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);