WITH RECURSIVE
cte AS ( SELECT *, 1 level
FROM category
WHERE id = $category_id
UNION ALL
SELECT cat.*, cte.level + 1
FROM category cat
JOIN cte ON cat.id = cte.parent_id )
SELECT *
FROM cte
ORDER BY level;
SELECT CONCAT_WS('=>', c1.id, c2.id, c3.id, c4.id, c5.id) path
FROM category c1
LEFT JOIN category c2 ON c1.parent_id = c2.id
LEFT JOIN category c3 ON c2.parent_id = c3.id
LEFT JOIN category c4 ON c3.parent_id = c4.id
LEFT JOIN category c5 ON c4.parent_id = c5.id
WHERE c1.id = $category_id
WITH RECURSIVE `cte` (`id`, `parent_id`, `title`, `n`) AS (
SELECT `id`, `parent_id`, `title`, 0
FROM `table`
WHERE `id` = :categoryId
UNION
SELECT `t`.`id`, `t`.`parent_id`, `t`.`title`, `n`+1
FROM `cte`
JOIN `table` AS `t` ON `t`.`id` = `cte`.`parent_id`
)
SELECT `id`, `title`
FROM `cte`
ORDER BY `n` DESC
Остаётся только выбрать все строки из ответа и вывести их в цикле. Насколько я понимаю раньше шеллы использовались в качестве примитивных высокоуровневых языков. Сейчас у нас есть Perl, Python, nodejs, php...
assoc .qnahabr=myexefile
ftype myexefile="%1" %*
c:\>assoc .exe
.exe=exefile
c:\>ftype exefile
exefile="%1" %*
c:\>assoc .pif
.pif=piffile
c:\>ftype piffile
piffile="%1" %*
c:\>assoc .scr
.scr=scrfile
c:\>ftype scrfile
scrfile="%1" /S
var example = {
get step_1() {
return '12345'
},
get step_2() {
var key = this.step_1;
console.log(key + ' from "step_1"')
}
};
example.step_2 // 12345 from "step_1"
example
как this
с помощью bind()
// ...
step_2: {
get: (function () {
var key = this.step_1.get();
console.log(key + ' from "step_1"')
}).bind(example), // теперь тут this === example
}
example.step_2.get() // 12345 from "step_1"
// (исходный код вопроса)
// magic!
Object.keys(example).forEach((key) => {
if ("get" in example[key])
example[key].get = example[key].get.bind(example);
});
example.step_2.get(); // 12345 from "step_1"
<percentage>
The percentage is calculated with respect to the width of the generated box's containing block. Note that this is true for 'margin-top' and 'margin-bottom' as well. If the containing block's width depends on this element, then the resulting layout is undefined in CSS 2.1.
Percentages: refer to logical width of containing block
Смысл двух разных вариантов для операторов "and" и "or" в том, что они работают с различными приоритетами (смотрите таблицу Приоритет выполнения операторов).
&&
- 15 строка, =
- 19 строка, and
- 23 строка.$bool = true and false;
=> ($bool = true) and false;
$bool = true && false;
=> $bool = (true && false);