Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For anyone looking for the answer, I took the code from Cody's link and made it work for me (since it wasn't working quite properly). Thanks Cody and Ciaran! Here it is:</p> <pre><code>&lt;cfquery name="get_folders" datasource="#application.dsn#"&gt; select folder_id, parent_folder_id, folder_name from folders order by folder_name &lt;/cfquery&gt; &lt;!--- Read all roots (no parent ID) ---&gt; &lt;cfquery name="get_parent_folders" dbtype="query"&gt; select folder_id, folder_name from get_folders where parent_folder_id is null &lt;/cfquery&gt; &lt;ul class="tree"&gt; &lt;cfloop query="get_parent_folders"&gt; &lt;cfset processTreeNode(folderId=get_parent_folders.folderId, folderName=get_parent_folders.folder_name) /&gt; &lt;/cfloop&gt; &lt;/ul&gt; &lt;cffunction name="processTreeNode" output="true"&gt; &lt;cfargument name="folderId" type="numeric" /&gt; &lt;cfargument name="folderName" type="string" /&gt; &lt;!--- Check for any nodes that have *this* node as a parent ---&gt; &lt;cfquery name="LOCAL.qFindChildren" dbtype="query"&gt; select folder_id, folder_name from get_folders where parent_folder_id = &lt;cfqueryparam value="#arguments.folderId#" cfsqltype="cf_sql_integer" /&gt; &lt;/cfquery&gt; &lt;li&gt;#arguments.folderName# &lt;cfif LOCAL.qFindChildren.recordcount&gt; &lt;!--- We have another list! ---&gt; &lt;ul&gt; &lt;!--- We have children, so process these first ---&gt; &lt;cfloop query="LOCAL.qFindChildren"&gt; &lt;!--- Recursively call function ---&gt; &lt;cfset processTreeNode(folderId=LOCAL.qFindChildren.folder_id, folderName=LOCAL.qFindChildren.folder_name) /&gt; &lt;/cfloop&gt; &lt;/ul&gt; &lt;/cfif&gt; &lt;/li&gt; &lt;/cffunction&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload