Как отсортировать темы по дате последнего сообщения "last_post_time" в "таблице #__kunena_topics"?
$query ='SELECT cat.name as cat_name,
cat.id as cat_id,
top.id as top_id,
top.subject as top_subject
FROM #__kunena_topics top
JOIN #__kunena_categories cat ON cat.id = top.category_id
WHERE cat.parent_id = '.$secid.' and cat.locked = 0 and top.locked = 0
AND (
SELECT COUNT(*)
FROM #__kunena_topics
WHERE top.category_id = category_id
AND top.id <= id
) <= 3';
Я пробовал, но это не работает:
..........
SELECT COUNT(*)
FROM #__kunena_topics
WHERE top.category_id = category_id
AND top.id <= id
) <= 3 ORDER BY top.last_post_time DESC';
результат
foreach ($this->items as $i => $object) :
?>
<?php if($object->cat_id != $lastcategory) { ?>
<div style="margin-top: 10px;border-bottom:3px solid black;">
<?php echo "category:". $object->cat_id; ?>
</div>
<?php } ?>
<div style="margin-top: 1px;border-bottom:1px solid black;"> <?php
echo "topic:". $object->top_subject;
$lastcategory = $object->cat_id;
?>
</div> <?php
endforeach; ?>
Теперь отображается
"CATEGORY 1"; "topic 3"; "topic 4"; "topic 5"; "CATEGORY 2"; "topic 55"; "topic 56"; "topic 57";
, и я хочу его
"CATEGORY 1"; "topic 5"; "topic 4"; "topic 3"; "CATEGORY 2"; "topic 57"; "topic 56"; "topic 55";
таблица: #__kunena_topics
:
результат: