PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Leigh Edwards   Simple Tree   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: working example
Class: Simple Tree
Display a collapsible tree of HTML links
Author: By
Last change: typo in array declarations
Date: 12 years ago
Size: 2,089 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My first styled page</title>
<style type="text/css">
.treeRoot {
   
}

.tree {
    text-align: left;
}

.treeBranch {
    margin-left: 40px;
    display: none;
}

.leafTitle {
    text-align: left;
    display: block;
    text-decoration: none;
}

.treeTitle {
    text-align: left;
    display: block;
    text-decoration: none;
}

.branchTitle {
    text-align: left;
    margin-left: 20px;
    display: block;
    text-decoration: none;
}
</style>

<script type="text/javascript">
function treeshow (limbid){
    toggle(limbid);
}

function toggle(div_id) {
    var el = document.getElementById(div_id);
    if (el.style.display == 'none') {
        el.style.display = 'block';
    } else {
        el.style.display = 'none';
    }
}
</script>

</head>

<body><?php
require_once ('class.tree.php');
$branchArray = array ("branch 1", "branch 2", "branch 3", "branch 4", "branch 5" );
$leafArray = array (array (0, 0, "leaf Text 1" ),
array (
0, 1, "leaf Text 2" ),
array (
2, 2, "leaf Text 3" ),
array (
3, 3, "leaf Text 4" ),
array (
4, 4, "leaf Text 5" ),
array (
0, 5, "leaf Text 6" ),
array (
4, 6, "leaf Text 7" ),
array (
4, 7, "leaf Text 8" ),
array (
4, 8, "leaf Text 9" ),
array (
4, 9, "leaf Text 10" ),
array (
3, 'link ID', "Link title goes in here" ),
array (
2, 10, "leaf Text 12" ),
array (
3, 11, "leaf Text 13" ),
array (
1, 12, "leaf Text 14" ),
array (
4, 13, "leaf Text 15" ),
array (
0, 14, "leaf Text 16" ),
array (
2, 15, "leaf Text 17" ), );
?>
There are the arrays that are used in this example:<br />
The branch array: <?php print_r($branchArray);?><br />
The leaf array: <?php print_r($leafArray);?><br />
<br />
A simple example of this working:<br />
<br />
<?php

$tree
= new tree ( "treeName" );
$tree->setBranches ( $branchArray );
$leaves = $leafArray;
$tree->buildTree ( $leaves, 0, 1, 2 );
$treeArray = $tree->getTree ();
echo
$treeArray ['treeOpen'];
foreach (
$treeArray ['branches'] as $branch ) {
    echo
$branch;
}
echo
$treeArray ['treeClose'];
?>
</body>
</html>