Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by CODE.TJ ( 13 years ago )
<php?
class MyClass {
public static function get_structure(){
DB::check(); global $db,$conf;
$structure=array();
if($db->ok()){
$sql="SELECT * FROM `structure` ORDER BY `sort`,`id`";
$res=$db->dbh->query($sql);
$res->setFetchMode(PDO::FETCH_ASSOC);
 if($res->rowCount()>0){
  while($r=$res->fetch()){
   $structure[$r['level']][$r['parent']][$r['id']]=$r['title'];
  }
 }
}
return $structure;
}

public static function xtree($structure,$level,$parent){
$result=""; $level=(string) $level; $parent=(string) $parent; $next_level=0;
if(isset($structure[$level][$parent])){
$result.="<ul>";
 foreach($structure[$level][$parent]  as $id => $title){
  $result.='  <li id="'.$id.'" class="'.$level.'">'.$title.'</li>';
  $next_level=$level+1;
  if(isset($structure[$next_level][$id])){$result.=MyClass::xtree($structure,$next_level,$id);}
 }
$result.="</ul>";
}
return $result;
}

}
?>

 

Revise this Paste

Your Name: Code Language: