| | |
|
|
|
Manipulating Tree Menu Display |
| message from David B on 24 Jul 2004 |
This script is looking better all the time; it displays the names of
every order, family, genus and species in the mammal kingdom, based on a
table in my database. Now I'm just trying to figure out how to
manipulate the data in various ways.
In particular...
1. Is there a way to insert tags, so that every parent's name would
display inside <div>[PARENT]</div> or <span>[PARENT]</span>, for example?
2. My database table includes a field named FamMamType, which denotes
every name's taxonomic position. For example, its type might be Order,
Family, Genus or Species. Is there some way to plug this into the
script, so that, for example, I could enclose the name of every order
with <span class="order"></span> and then give it bold type and perhaps
a colored background?
3. Is it also possible to access and manipulate individual names? If I
only want to give the wolf, Canis lupus, a yellow background, how would
I do it?
Thanks.
[PHP]
<pre class="pretax">
<?php
function display_children($parent = '', $level = 0)
{
global $nodes;
if ($parent) {
echo str_repeat(' ', $level), $parent, "\n";
}
if (isset($nodes[$parent])) { foreach ($nodes[$parent] as $child){
display_children($child, $level + 1);
}
$nodes = array();
$result = mysql_query('SELECT FamMamParent, FamMamName FROM fammammals');
while ($row = mysql_fetch_assoc($result)) {
$nodes[$row['FamMamParent']][] = $row['FamMamName'];
}
display_children();
?>
</pre>
[/PHP]
|
|
Archived message: Manipulating Tree Menu Display (Macromedia Dreamweaver)