Welcome Guest, Not a member yet? Register   Sign In
sub-categories and sub-subcategories on a associative array with CI
#16

[eluser]MEM[/eluser]
Sorry. :S I forgot to post de model, here please:

I'm really sorry. Sad



Code:
<?php

class M_Categoria extends Model
{
public function __construct()
{
parent::__construct();
$this->load->database();
}


public function getAllCategorias()
{

$query=$this->db->get(');

if($query->num_rows()>0)
{
return $query->result();
}
}

public function getCategoria($id_cat)
{

$query = $this->db->get_where(', array('id_cat'=>$id_cat));

if ($query->num_rows() > 0)
{
$record = $query->row();
}

return $record;
}


public function getCategoriasPrincipais()
{

$this->db->where('parent_id_cat', NULL);

$this->db->where('activa_cat =', 1);


$query=$this->db->get(');

if($query->num_rows()>0)
{
return $query->result();
}
}


public function getSubCategorias($id_cat)
{

$strSQL = 'SELECT c.id_cat,c.nome_cat,c.parent_id_cat FROM categoria c';
$query = $this->db->query($strSQL);

$arrQuery = $query->result_array();


return $this->_parseResultTree($id_cat,$arrQuery, $intRunner=0);

}



private function _parseResultTree($intParentId,&$arrRows,$intRunner)
{

$arrChildren = array();


for($i=0;$i<count($arrRows);$i++)

{

if($intParentId == $arrRows[$i]['parent_id_cat'])
{

$arrChildren = array_merge($arrChildren,array_splice($arrRows,$i--,1));
}
}


$intChildren = count($arrChildren);


if($intChildren != 0)
{

for($i=0;$i<$intChildren;$i++)
{

$arrChildren[$i]['children'] = $this->_parseResultTree($arrChildren[$i]['id_cat'],$arrRows,$intRunner++);
}
}

return $arrChildren;

}

}//end of class

?&gt;


I had to do some css and forms for another site, more urgent than this one, and I end up forgetting this one. I'm really sorry for having this forgotten for so long. Sad

Good Luck on you case, because now that I'm back, I must confess that I'm still stuck on this one.



Regards,
Márcio


Messages In This Thread
sub-categories and sub-subcategories on a associative array with CI - by El Forum - 10-12-2009, 05:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB