Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
dRmx 16.09.2003 22:50
^MAIN:pSQL.left_join[from;forum_message_body;forum_message.forum_message_id = forum_message_body.forum_message_id]А вообще полный код
@auto[] $connect_string[mysql://root@localhost/forum] @getMessageById[id] $result[^table::sql{ SELECT forum_message.forum_message_id, parent_id, thread_id, title, author, email, dt_published, forum_message_body.body FROM forum_message ^MAIN:pSQL.left_join[from;forum_message_body;forum.forum_message_id = forum_message_body.forum_message_id] WHERE ^MAIN:pSQL.left_join[where;forum_message_body;forum.forum_message_id = forum_message_body.forum_message_id] forum_message.forum_message_id = ^id.int(0) AND is_published = 1 }] @getMessagesByParent[parent_id;limit] $result[^table::sql{ SELECT forum_message.forum_message_id, parent_id, thread_id, title, author, email, dt_published, forum_message_body.forum_message_id AS is_not_empty FROM forum_message ^MAIN:pSQL.left_join[from;forum_message_body;forum_message.forum_message_id = forum_message_body.forum_message_id] WHERE ^MAIN:pSQL.left_join[where;forum_message_body;forum_message.forum_message_id = forum_message_body.forum_message_id] ^if(def $parent_id){parent_id = ^parent_id.int(0) AND} is_published = 1 ORDER BY dt_published }[^if(^limit.int(0)){$.limit(^limit.int(0))}]] @getMessagesByThread[thread] $result[^table::sql{ SELECT forum_message.forum_message_id, parent_id, thread_id, title, author, email, dt_published, forum_message_body.forum_message_id AS is_not_empty FROM forum_message ^MAIN:pSQL.left_join[from;forum_message_body;forum_message.forum_message_id = forum_message_body.forum_message_id] WHERE ^MAIN:pSQL.left_join[where;forum_message_body;forum_message.forum_message_id = forum_message_body.forum_message_id] ^if($thread is table){ ^if($thread){thread_id IN (^thread.menu{$thread.thread_id}[,]) AND} }{ thread_id = ^thread.int(0) AND } is_published = 1 ORDER BY dt_published DESC }] @printMessagesByParent[messages;parent_id][levelmessages] $levelmessages[^messages.select($messages.parent_id == $parent_id)] ^levelmessages.menu{ ^printTreeItem[$levelmessages.fields;^printMessagesByParent[$messages;$levelmessages.forum_message_id]] } @printTreeItem[message;body] $result[<tree-item id="$message.forum_message_id" date="$message.dt_published" is-empty="^if($message.is_not_empty){0}{1}"> <title>$message.title</title> <author>$message.author</author> <email>$message.email</email> $body </tree-item>] @main[] # достаем не более 20 корневых сообщений (parent_id == 0) $rootMessages[^getMessagesByParent[0;20]] # достаем все сообщения в тредах, которые мы только что достали $messages[^getMessagesByThread[$rootMessages]] # собственно выводим все данные о сообщениях в виде дерева ^printMessagesByParent[$messages;0]