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:
while it's supposed this: (obviously not styled, point)
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
Post a Comment