php - Padding when sorting categories fails and mis-sorts -


i'm trying code channel viewer teamspeak 3 server (which has parent , child channels/categories, , child channels child channels , on), when trying style , add padding depends on is, fails , turns out this:

how looks

while it's supposed this: (obviously not styled, point)

how it's supposed look

here's code:

private $_allchannels   = array(); private $_allclients    = array();  private function showchannels($parentid, $padding) {     $response   = '';      foreach ($this->_allchannels $channel) {         $channelparent  = $channel['pid'];         $channelid      = $channel['cid'];         $channelname    = $channel['name'];          if ($channelparent == $parentid) {             $response   .= '<span style="margin-left: ' . $padding*2 . 'em;">' . $channelname . '</span><br>';             $response   .= $this->showchannels($channelid, $padding++);         }     }      return $response; }  public function index() {     $teamspeakserver    = teamspeak3::factory("serverquery://user:pass@ip:queryport/?server_port=serverport");      $allclients         = $teamspeakserver->clientlist(['client_type' => 0]);     $allchannels        = $teamspeakserver->channellist();      foreach ($allchannels $channel) {         array_push($this->_allchannels, array('pid' => $channel['pid'], 'name' => $channel['channel_name'], 'cid' => $channel['cid']));     }      echo $this->showchannels(0, 0); } 

i'll appreciate help, thanks!

reading on code, adding padding. $padding++ increment value , save $padding. on next loop keep adding again. if had guess, want $padding+1 add 1, not overwrite $padding new $padding+1 value.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -