Unix Technical Forum

building indentation in hierarchical data

This is a discussion on building indentation in hierarchical data within the MySQL forums, part of the Database Server Software category; --> I'm trying to improve my ability to represent hierarchical data. Mike Hillyer's article (dev.mysql.com/tech-resources/articles/hierarchical-data.html) on hierarchical data describes a ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:18 AM
strawberry
 
Posts: n/a
Default building indentation in hierarchical data

I'm trying to improve my ability to represent hierarchical data.

Mike Hillyer's article
(dev.mysql.com/tech-resources/articles/hierarchical-data.html) on
hierarchical data describes a process of indenting nested set results
based upon their depth within the data tree. The point here is that the
indentation is constructed in MySQL.

I was just wondering if anyone had managed something similar using the
adjacency list model (ALM) and (excuse my ignorance here) a trigger,
stored procedure or a bit of php - but again, building the indentation
in MySQL.

On a related point, Gijs Van Tulder's article
(http://www.sitepoint.com/article/hie...-data-database) purports to
build the indentation in php (using the ALM) but, unless I'm missing
something, the list he builds does not seem to be indented. Am I
missing something?

Anyone get what I'm talking about? Any more info about either the php
or mysql approach greatly appreciated.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:19 AM
strawberry
 
Posts: n/a
Default Re: building indentation in hierarchical data


strawberry wrote:
> I'm trying to improve my ability to represent hierarchical data.
>
> Mike Hillyer's article
> (dev.mysql.com/tech-resources/articles/hierarchical-data.html) on
> hierarchical data describes a process of indenting nested set results
> based upon their depth within the data tree. The point here is that the
> indentation is constructed in MySQL.
>
> I was just wondering if anyone had managed something similar using the
> adjacency list model (ALM) and (excuse my ignorance here) a trigger,
> stored procedure or a bit of php - but again, building the indentation
> in MySQL.
>
> On a related point, Gijs Van Tulder's article
> (http://www.sitepoint.com/article/hie...-data-database) purports to
> build the indentation in php (using the ALM) but, unless I'm missing
> something, the list he builds does not seem to be indented. Am I
> missing something?
>
> Anyone get what I'm talking about? Any more info about either the php
> or mysql approach greatly appreciated.


Well, here's Gijs's solution modified to provide the indentation (I
think) he intended...

// $parent is the parent of the children we want to see
// $level is increased when we go deeper into the tree,
// used to display a nice indented tree
function display_children($parent, $level) {
// retrieve all children of $parent
$query = 'SELECT title FROM tree WHERE parent="'.$parent.'";';
//echo $query;
$result = mysql_query($query);

// display each child
while ($row = mysql_fetch_array($result)) {
echo "<br>";
// indent and display the title of this child
echo str_repeat("&nbsp;&nbsp;",$level).$row['title']."\n";

// call this function again to display this
// child's children
display_children($row['title'], $level+1);
}
}

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com