SELECT `a`.`name`, `b`.`total`, `c`.`unread`
FROM `table1` AS `a`
LEFT JOIN (SELECT `table1_id`, `COUNT(*) AS `total`
FROM `table2`
GROUP BY `table1_id`) AS `b` ON `b`.`table1_id` = `a`.`id`
LEFT JOIN (SELECT `table1_id`, COUNT(*) AS `unread`
FROM `table2`
WHERE `read` = 0
GROUP BY `table1_id`) AS `c` ON `c`.`table1_id` = `a`.`id`
WHERE `a`.`user_id` = 1;
function sub7(left, right, level, depth) {
$list = список прямых потомков (`left_branch` >= :left_key AND `right_branch` <= :right AND `level` = :level+1);
foreach($list as $item) {
echo "<li>{$item['name']}";
if (depth < 7) {
echo "<ul>";
sub7($item['left'], $item['right'], $item['level'], $depth+1);
echo "</ul>";
}
}
}
echo "Команда:<ul>";
sub7($current_user_left, $current_user_right, $current_user_level, 0);
echo "</ul>"
word_id | language | word
--------+----------+---------
1 | RU | почему
1 | FR | pourquoi
1 | EN | how
1 | EN | why so
1 | DE | warum