1. 程式人生 > >遞迴,逆推,由子選單查父級選單

遞迴,逆推,由子選單查父級選單

///////遞迴逆推由子集選單查父級選單
//控制器
//查詢父級ID
function select_area_father($father_id){$name='';
if ($father_id == "0")//判斷欄位父級ID是否為0,為0說明是一級選單
return "";
$sql = "select id,name,father_id from area where id= $father_id";//根據欄位父級ID查詢父級
$result = mysql_query($sql);$rows=mysql_fetch_assoc($result);
$name = "-->" . $rows["name"
] . $name; $this->father_str($rows["father_id"]);//使用遞迴, return $name; } //HTML頁面
<input type="hidden" name="area_position" value="<?=$area_id?>" id="area_position" />//接收連結傳輸的子集ID
<? $group->father_str($area_id);?>//呼叫控制器方法並傳給引數
<? echo $group->Name;?>//顯示出來