|
|
|
| мне нужно чтобы дочерний блок div вкладывался в блок к родителю. подскажите что нужно сделать
function getCategory() {
$query = mysql_query("SELECT * FROM `users`");
$result = array();
while ($row = mysql_fetch_array($query)) {
$result[$row["created_by"]][] = $row;
}
return $result;
}
//В переменную $category_arr записываем все категории
$category_arr = getCategory();
/**
* Вывод дерева
* @param Integer $parent_id - id-родителя
* @param Integer $level - уровень вложености
*/
function outTree($parent_id, $level) {
global $category_arr; //Делаем переменную $category_arr видимой в функции
if (isset($category_arr[$parent_id])) { //Если категория с таким parent_id существует
foreach ($category_arr[$parent_id] as $value) { //Обходим
/**
* Выводим категорию
* $level * 25 - отступ, $level - хранит текущий уровень вложености (0,1,2..)
*/
if($level==0) {
echo"
<div class='general_block_for_users' parent=" . ($level * 25) . "><div style='margin-left:" . ($level * 25) . "px; width: 120px; text-align:left' class='block_for_users' >
<div>
<div class='trg_no_active' data=" . ($level * 25) . " ></div>
<div style='float:left'>" . $value['login'] . "</div>
</div></div>
<div class='block_for_users' style='width: 80px;'>" . $value['password'] . "</div>
<div class='block_for_users' style='width: 200px;'>" . $value['fio'] . "</div>
<div class='block_for_users' style='width: 40px;'>" . $value['price_A'] . "</div>
<div class='block_for_users' style='width: 40px;'>" . $value['price_B'] . "</div>
<div class='block_for_users' style='width: 40px;'>" . $value['price_C'] . "</div>
<div class='block_for_users' style='width: 40px;' >" . $value['price_D'] . "</div>
<div class='block_for_users' style='width: 40px;'>" . $value['price_trailer'] . "</div>
<div class='block_for_users' style='width: 120px;'>" . $value['city'] . "</div>
<div class='block_for_users' style='width: 100px; padding-top:3px;'><div class='icon_for_blocked'></div><div class='icon_for_add_users'></div><div class='icon_for_add_request'></div></div>
<div class='block_for_users' style='width: 150px;'><span>Изменить</span> </div>
</div>
";
} else {
echo "<div class='general_block_for_users' parent=" . ($level * 25) . ">
<div style='margin-left:" . ($level * 25) . "px; width: 120px;' data=" . ($level * 25) . " class='block_for_users'>
<div class='trg_no_active' data=" . ($level * 25) . " ></div>
<div style='float:left'>" . $value['login'] . "</div>
</div>
<div class='block_for_users' style='width: 100px; padding-top:3px; '><div class='icon_for_blocked'></div><div class='icon_for_add_users'></div><div class='icon_for_add_request'></div></div>
<div class='block_for_users' style='width: 150px;' ><span>Изменить</span> </div>
</div>
";
}
$level = $level + 1; //Увеличиваем уровень вложености
//Рекурсивно вызываем эту же функцию, но с новым $parent_id и $level
outTree($value['id'], $level);
$level = $level - 1; //Уменьшаем уровень вложености
}
}
}
|
| |
|
|