1
如何添加單選按鈕遞歸,以便我可以選擇和刪除它們?遞歸PHP單選按鈕
數據庫:
ID | NAME | PARENT
1 | General | 0
2 | Enteprise Dept | 0
3 | Sales Dept | 0
4 | Collection | 3
5 | Company | 2
6 | Collection | 5
功能:
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);
}
調用:
echo list_project_category("category",0,"",$parent,0);
結果:(數量實際上是部門根據項目總數)
General >> 0
Enterprise Dept >> 0
Enterprise Dept >> company >> 1
Enterprise Dept >> company >> collection >> 0
Sales Dept >> 0
Sales Dept >> collection >> 1
我想按鈕添加到他們。
[從數據庫結果生成多維數組的遞歸函數](http://stackoverflow.com/questions/8587341/recursive-function-to-generate-multidimensional-array-from-database-result) – Prix