1

how can I add radio buttons to recursion so I can select and delete them?

the database :

ID  |  NAME          |  PARENT
1   |  General       |    0  
2   | Enteprise Dept |    0
3   | Sales Dept     |    0
4   | Collection     |    3
5   | Company        |    2
6   | Collection     |    5

the function :

function list_project_category($name,$parent,$parent_name,$default,$rec=0)
{
$temp="";
if($rec==0)
{
    //just_testing_code
}
$sql = "select id,name from system_categories where parent=$parent";
$result = mysql_query($sql) or die("error:list_project_category");
while($row=mysql_fetch_array($result))
{
    $ids=$row['id'];
    $names=$row['name'];

    $sql3 = mysql_query("SELECT COUNT(category) as cat FROM system_tables WHERE     category='$ids'");
    while($row1=mysql_fetch_assoc($sql3))
    {
        $cat_count=$row1['cat'];

        $def=($default==$row[0])?"":"";
        $par=($parent_name=="")?"":"$parent_name >> ";
        $temp.="</br>"."$def $par".$row[1]." >> $cat_count";
        $temp.=list_project_category($name,$row[0],$par.$row[1],$default,$rec+1);
    }
}
if($rec==0)
{
     //just_testing_code
}
return ($temp);
}

the calling :

echo list_project_category("category",0,"",$parent,0);

the result : (the number is actually the total projects under the department)

General >> 0
Enterprise Dept >> 0
Enterprise Dept >> company >> 1
Enterprise Dept >> company >> collection >> 0
Sales Dept >> 0
Sales Dept >> collection >> 1 

i want to add buttons to them.

  • [Recursive function to generate multidimensional array from database result](http://stackoverflow.com/questions/8587341/recursive-function-to-generate-multidimensional-array-from-database-result) – Prix Jul 29 '13 at 07:24

1 Answers1

0

ASSUMPTION 1:

If I understand correctly, when deleting a parent, you want to delete all it's children so that they are not orphaned.

ASSUMPTION 2:

You want to use checkboxes to be able to select and delete multiple items.

SOLUTION:

  1. Define a form submitting to your deletecategories.php script.
  2. Within a form print your category labels along with a checkbox that has id of your category as it's value
  3. On submit, in your deletecategories.php, capture the id submitted by the form and using sql, recursively delete category by id along with all it's descendants.

NOTE: You could print the HTML either directly inside of your recursive function, or to make things cleaner have your recursive function return a flat array of "label"=>"id" pairs and then iterate that inside of your html template.

Lex Podgorny
  • 2,598
  • 1
  • 23
  • 40