Please analyze the following code. This is being used in CodeIgniter framework...
$results["rows"]=$this->Category_model->getAll();
$i=0;
while($i<count($results["rows"]))
{
//$parentids[]=$results["rows"][$i]->cat_id;
$disparray[]=array(
"cat_id" => $results["rows"][$i]->cat_id,
"cat_name" => $this->Category_model->fetchcatinfo($results["rows"][$i]->cat_id, "cat_name"),
"cat_parent_id" => $this->Category_model->fetchcatinfo($results["rows"][$i]->cat_id, "cat_parent_id"),
"cat_desc" => $this->Category_model->fetchcatinfo($results["rows"][$i]->cat_id, "cat_desc"),
"cat_num_posts" => $this->Category_model->fetchnumposts($results["rows"][$i]->cat_id),
"cat_parent_id_name"=>$this->Category_model->fetchcatinfo($this->Category_model->fetchcatinfo($results["rows"][$i]->cat_id, "cat_parent_id"), "cat_name")
);
$array=explode(",",$this->Category_model->fetchallkids($results["rows"][$i]->cat_id,0));
foreach($array as $item)
{
if(strlen($item)>0)
{
$spacecount=substr_count($item," ");
$id=str_replace(" ","",$item);
$spaces=array();
while($spacecount>=0)
{
$spaces[]=" ";
$spacecount--;
}
$disparray[]=array(
"cat_id" => $id,
"cat_name" => implode($spaces).$this->Category_model->fetchcatinfo($id, "cat_name"),
"cat_parent_id" => $this->Category_model->fetchcatinfo($id, "cat_parent_id"),
"cat_desc" => $this->Category_model->fetchcatinfo($id, "cat_desc"),
"cat_num_posts" => $this->Category_model->fetchnumposts($id),
"cat_parent_id_name"=>$this->Category_model->fetchcatinfo($this->Category_model->fetchcatinfo($id, "cat_parent_id"), "cat_name")
);
}
}
$i++;
}
// echo "Parent ID : ".$parentids[0]["cat_id"]."<br><br>";
// echo "The array being passed to the view part: <br>";
foreach($disparray as $item)
{
$finalarray["row"]=implode("|",$item);
}
$this->load->view("category", $finalarray);
In the view section when i try to output the array like print_r($row). It shows only the last element. When i try to display the contents of the $disparray in the controller part, its working fine.
I would like to know if instead of making and transferring $finalarray if i just transfer the $disparray how will i be able to display the contents of the array in the view part? Thanks in advance