国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 邏輯算法 > 正文

php:樹形結構的算法 4

2024-09-08 23:18:45
字體:
來源:轉載
供稿:網友
  <?php
  /**
  * 顯示列表
  * @access public
  */
  function displist()
  {
  //不縮進的顯示方式
  // $this->misdisplistindex = true;
  // echo('<p align="right"><a href="?action=new&part=role">增加新角色</a>  </p>'); _fcksavedurl=""?action=new&part=role">增加新角色</a>  </p>');"
  //
  // $this->mlisttitle = '用戶角色列表';
  // $this->setdataoption('list');
  //
  // $this->setquerytable( array($this->mtableuserrole) );
  //
  // //查詢順序
  // $this->setqueryorder( 'asc', $this->mtableuserrole, 'sequence' );
  //
  // $this->query('list');
  // parent::displist();
  
  // //另外一種顯示方式,用數組作為堆棧,a: 壓棧時存role,壓完就刪除source
  // $this->checkproperty('mrdb');
  // $this->checkproperty('mrsql');
  // $this->mrsql->select('role, title, parent');
  // $this->mrsql->from($this->mtableuserrole);
  // $this->mrsql->orderby('parent, sequence');
  // $this->mrs = $this->mrdb->execute($this->mrsql->sql());
  // if (0 < count($this->mrs))
  // {
  // $source = & $this->mrs->getarray(); //數字索引
  // $stack = array(''); //堆棧
  // $stacki = array(-1); //和堆棧對應,記錄堆棧中數據在樹中的層次
  // $target = array();
  // while (0 < count($stack))
  // {
  // $item = array_shift($stack);
  // $lev = array_shift($stacki);
  // if (!empty($item))
  // {
  // //在這里把加工過的數據放到target數組
  // array_push($target, str_repeat(' ', $lev) . $item);
  // //$s1 = str_repeat(' ', $lev) . $item;
  // }
  // $del = array(); //要從$source中刪除的節點
  // $ar = array(); //需要添加到堆棧中的節點
  // foreach ($source as $key=>$val)
  // {
  // //尋找匹配的子節點
  // if (empty($item))
  // {
  // $find = empty($source[$key]['parent']);
  // }
  // else
  // {
  // $find = ($item == $source[$key]['parent']);
  // }
  // if ($find)
  // {
  // array_unshift($ar, $source[$key]['role']);
  // $del[] = $key;
  // }
  // }
  // foreach ($ar as $val)
  // {
  // array_unshift($stack, $val);
  // array_unshift($stacki, $lev + 1);
  // }
  // foreach ($del as $val)
  // {
  // unset($source[$val]);
  // }
  // echo(implode(', ', $stack) . '<br />' . implode(', ', $stacki) . '<br />' . implode(', ', $target) . '<br /><br />');
  // }
  // debug_array();
  // }
  // else
  // {
  // echo('<center>沒有檢索到數據</center>');
  // }
  
  //另外一種顯示方式,用數組作為堆棧,b: 壓棧時存數組索引,出棧并使用完后再刪除source
  $this->checkproperty('mrdb');
  $this->checkproperty('mrsql');
  $this->mrsql->select('role, title, parent');
  $this->mrsql->from($this->mtableuserrole);
  $this->mrsql->orderby('parent, sequence');
  $this->mrs = $this->mrdb->execute($this->mrsql->sql());
  if (!empty($this->mrs) && !$this->mrs->eof)
  {
  $source = & $this->mrs->getarray(); //數字索引
  $stack = array(-1); //堆棧
  $stacki = array(-1); //和堆棧對應,記錄堆棧中數據在樹中的層次
  $target = array();
  while (0 < count($stack))
  {
  $item = array_shift($stack);
  $lev = array_shift($stacki);
  if (-1 != $item)
  {
  //在這里把加工過的數據放到target數組
  $s1 = str_repeat(' ', $lev) . '<a href="?action=disp&part=role&role=' . $source[$item]['role'] . '">' . $source[$item]['title'] . '</a>';
  $s2 = '<a href="?action=edit&part=role&role=' . $source[$item]['role'] . '">編輯</a> <a href="?action=delete&part=role&role=' . $source[$item]['role'] . '">刪除</a>';
  array_push($target, array($s1, $s2));
  }
  $del = array(); //要從$source中刪除的節點
  $ar = array(); //需要添加到堆棧中的節點
  foreach ($source as $key=>$val)
  {
  //尋找匹配的子節點
  if (-1 == $item)
  {
  $find = empty($source[$key]['parent']);
  }
  else
  {
  $find = ($source[$item]['role'] == $source[$key]['parent']);
  }
  if ($find)
  {
  array_unshift($ar, $key);
  }
  }
  foreach ($ar as $val)
  {
  array_unshift($stack, $val);
  array_unshift($stacki, $lev + 1);
  }
  //從source中刪除
  unset($source[$item]);
  //echo(implode(', ', $stack) . '<br />' . implode(', ', $stacki) . '<br />' . implode(', ', $target) . '<br /><br />');
  }
  //輸出
  echo('<p align="right"><a href="?action=new&part=role">增加新角色</a>  </p>');
  array_unshift($target, array('角色', '操作'));
  $this->checkproperty('mrlt');
  $this->mrlt->setdata($target);
  $this->mrlt->mlisttitle = '用戶角色列表';
  $this->mrlt->misdispindex = false;
  $this->mrlt->disp();
  }
  else
  {
  echo('<center>沒有檢索到數據</center>');
  }
  } // end of function displist
  ?>



上一篇:php:樹形結構的算法 3

下一篇:返回列表

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安乡县| 天全县| 康平县| 桐庐县| 满洲里市| 永定县| 惠东县| 仪征市| 如皋市| 天津市| 沾化县| 陈巴尔虎旗| 多伦县| 沁阳市| 大英县| 新泰市| 聂荣县| 苏尼特左旗| 宝兴县| 罗甸县| 尼勒克县| 荣成市| 溆浦县| 施甸县| 福贡县| 五家渠市| 商水县| 分宜县| 扎兰屯市| 西乌| 衡山县| 富锦市| 南充市| 额敏县| 内乡县| 四川省| 安塞县| 长武县| 孝昌县| 吴江市| 芮城县|