-2

Respected Sir, I am getting nested categories in a dropdown by the following function.

<?php
/* 
Function lists all items in table tb_category
- id
- pid
- name
*/
require_once("../config.php");
mysql_connect($mysql_hostname,$mysql_user,$mysql_password);
mysql_select_db($mysql_database); 

function RecursiveCat($pid)
{
static $level=0;
static $strid="";
static $strname="";
$sql=mysql_query("select * from tb_category where pid = '$pid' order by name ");
while($row=mysql_fetch_assoc($sql))
{
$id=$row['id'];
$level--;
$pad="";
for($p=1;$p<($level*-1);$p++) $pad.="&nbsp;&nbsp;&nbsp;- ";
$strname.='<option value="'.$row['id'].'">'.$pad.$row['name'].'</option>';
$rid=RecursiveCat($id);
$strid[]=$row['id'];
$level++;
}
return $strname;
}
echo '<select name="dropdown_categories">';
echo RecursiveCat(0);
echo '</select>';
?>

And the screenshot is http://guest.webege.com/screenshots/dropdown_categories.jpg

Sir, my request is how to make the root category starts from one particular id ?( from employees in that screen shot example image) I hope you will consider my request and guide me. yours faithfully murulimadhav

4

1 回答 1

2

看起来你的函数 RecursiveCat($pid) 已经有它的特殊参数。只需替换RecursiveCat(0)RecursiveCat($yourID).

于 2013-09-13T04:49:39.530 回答