Jump to content

How do I make a tree view from MySQL and PHP


projectdeploy

Recommended Posts

I have an application in the making that needs to show a treeview of files and directories.

 

I have it all working based on an <ul>. Each <li> is a sub file .

 

I have a table set up with:

name, parent, type, user, content, project, date, id

 

I set up the DB to set the parent as the id of it's parent (e.g. Directory "A" has an id of "2" and parent of "0" and directory "B" has an id of "20" and a parent of "2". B would be nested inside of A because it's parent matches it's id).

 

Here is a sample of what I want the markup to be like:

 

<ul>
<li class="folder">
	The Project Name
	<ul>
		<li class="folder">
			css
			<ul>
				<li class="file">style.css</li>
				<li class="file">thickbox.js</li>
			</ul>
		</li>
		<li class="folder">
			includes
			<ul>
				<li class="folder">
					functions
					<ul>
						<li class="file">math.php</li>
						<li class="file">mysql_connect.php</li>
					</ul>
				</li>
				<li class="file">header.php</li>
				<li class="file">sidebar.php</li>
				<li class="file">footer.php</li>
			</ul>
		</li>
	</ul>
</li>
</ul>

I can not figure this out. Does anyone know how to sort recursively like this?!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.