Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Andre 11.11.2008 19:33 / 11.11.2008 19:35
Насколько неоптимальным является данный код, выводящий через запятую всех детей заданного родителя в БД. У меня такое чувство, что это не самый простой вариант.# SELECT ALL CHILDS OF PARENT # Childs — id # Parents — parent_id # # Using: # ^modLib:Childs[ # $.cTable[] # $.cParentId() # ] # -------------------------------------------------------------------------------------------------- @Childs[h] $cElements[^cTreeGetElements[$h]] $hTree[^cTreeCreateHash[$cElements]] $result[^cTreePrintElementsByParent[$hTree;$h]${h.cParentId}] @cTreeGetElements[h] $result[^oSql.table{SELECT * FROM $h.cTable}] @cTreeCreateHash[tElements] $result[^tElements.hash[parent_id][$.distinct[tables]]] @cTreePrintElementsByParent[hTree;h] ^if($hTree.[$h.cParentId]){ ^hTree.[$h.cParentId].menu{ cTreePrintItem[$hTree.[$h.cParentId].fields;$h;^if($hTree.[$hTree.[$h.cParentId].id]){^cTreePrintElementsByParent[$hTree;$.cParentId($hTree.[$h.cParentId].id) $.cTable[$h.cTable]]}] } } @cTreePrintItem[hTree;h;sBody] $result[${hTree.id},$sBody]Мне это нужно для последующего использования в запросе к MySQL в IN (1,2,3,4,...).