function get_top_parentid($id){ $r = M('navclass')->where('id = '.$id)->field('id,f_id')->find(); if($r['f_id'] != '0') return get_top_parentid($r['f_id']); return $r['id'];}
echo get_top_parentid($postcid);