Welcome Guest, Not a member yet? Register   Sign In
delete n level categories ?
#1

[eluser]Zeeshan Rasool[/eluser]
Hi dear friends, hope you will be alright, I want to delete n level categories in my CI site can any one help me ?

What i Need

ID Name ParentID
1 Dress 0
2 Shirts 1
3 Tie 2
4 Red Color 3
5 Small 4

I want to delete Shirts with Tie RedColor and Small bcoz they comes under the category Shirts which we are going to delete.

Very thanks
#2

[eluser]richthegeek[/eluser]
It's easiest to do this with a modified pre-order tree structure (linky linky), but I suspect you'd need to this programmatically do to it's recursive nature;

Code:
function delete_category( $id, $table = "Categories" )
{
    $query = $this->db->where( "ParentID"=>$id )->get( $table )->result();
    foreach( $query as $row ) delete_category( $row->ID );
    $this->db->delete( $table, array( "ID"=>$id ) );
}

That should do it.
#3

[eluser]Zeeshan Rasool[/eluser]
Great ! it really helped me Very thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB