WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : This code displays a graphical tree (similar to that of Windows' Explorer) from the contents of a database table.
Categories : Algorithms, PHP Update Picture
Stig Bakken
Date : Jan 17th 1999
Grade : Be the 1st to grade this Code Example
Viewed : 8134
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Stig Bakken
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php // -*- C++ -*-

/* Here are the database definitions (for Solid) that i use in this code.
* It should not be hard to adapt it to another database.
*/

/*
CREATE TABLE dirent_types (
id INTEGER NOT NULL,
icon VARCHAR(50),
name VARCHAR(50),
PRIMARY KEY(id)
);

INSERT INTO dirent_types VALUES(1, 'folderclosed', 'Directory');
INSERT INTO dirent_types VALUES(2, 'document', 'File');

CREATE TABLE directory (
id INTEGER NOT NULL,
parent INTEGER REFERENCES directory(id),
name VARCHAR(200),
icon VARCHAR(50),
type INTEGER REFERENCES dirent_types(id),
url VARCHAR(200),
PRIMARY KEY(id)
);

DROP INDEX directory_idx;

CREATE UNIQUE INDEX directory_idx ON directory(parent, name);

CREATE SEQUENCE dirent_id;

"CREATE PROCEDURE insert_dir_entry
(name VARCHAR, parent INTEGER, type INTEGER)
RETURNS(id INTEGER)
BEGIN
EXEC SQL WHENEVER SQLERROR ABORT;
EXEC SEQUENCE dirent_id.NEXT INTO id;
EXEC SQL PREPARE c_insert
INSERT INTO directory
(id, parent, type, name)
VALUES(?, ?, ?, ?);
EXEC SQL EXECUTE c_insert USING (id, parent, type, name);
EXEC SQL DROP c_insert;
END";

CALL insert_dir_entry('My Computer', NULL, 1);
CALL insert_dir_entry('Network Neighbourhood', NULL, 1);
CALL insert_dir_entry('lucifer.guardian.no', 2, 1);
CALL insert_dir_entry('rafael.guardian.no', 2, 1);
CALL insert_dir_entry('uriel.guardian.no', 2, 1);
CALL insert_dir_entry('Control Panel', NULL, 1);
CALL insert_dir_entry('Services', 6, 1);
CALL insert_dir_entry('Apache', 7, 2);
CALL insert_dir_entry('Solid Server 2.2', 7, 2);

*/

function icon($icon, $name = '', $width = 0, $height = 0) {
global $DOCUMENT_ROOT;
$icon_loc = '/pics/menu';
$file = "$DOCUMENT_ROOT$icon_loc/$icon.gif";
if (!$width || !$height) {
$iconinfo = getimagesize($file);
if (!$width) {
$width = $iconinfo[0];
}
if (!$height) {
$height = $iconinfo[1];
}
}
printf( '<img%s border=0 align=top src="/pics/menu/%s.gif" '.
'width="%d" height="%d">', $name ? " name=\"$name\"" : '',
$icon, $width, $height);
}

/*
* Displays, recursively, the contents of a tree given a starting
* point.
*
* Parameters:
* $parent - the parent node (not listed in the directory). Node
* 0 is the root node.
*
* $maxdepth (optional) - maximum number of recursion levels. -1
* (the default value) means no limits.
*
* $ancestors (optional) - an array of the ancestor nodes in the
* current branch of the tree, with the node closest to the
* top at index 0.
*
* Global variables used:
* $child_nodes
* $node_data
* $last_child
*
* Global variables modified:
* The array pointers in $child_nodes will be modified.
*/
function display_directory($parent, $showdepth = 0, $ancestors = false) {
global $child_nodes, $node_data, $last_child;
reset($child_nodes[$parent]);
$size = sizeof($child_nodes[$parent]);
$lastindex = $size - 1;
if (!$ancestors) {
$ancestors = array();
}
$depth = sizeof($ancestors);
printf( '<div id="node_%d" class="dirEntry" visibility="%s">',
$parent, $showdepth > 0 ? 'show' : 'hide');
while (list($index, $node) = each($child_nodes[$parent])) {
/*
For each of the uptree nodes:
If an uptree node is not the last one on its depth
of the branch, there should be a line instead of a blank
before this node's icon.
*/
for ($i = 0; $i < $depth; $i++) {
$up_parent = (int)$node_data[$ancestors[$i]][ 'parent'];
$last_node_on_generation = $last_child[$up_parent];
$uptree_node_on_generation = $ancestors[$i];
if ($last_node_on_generation == $uptree_node_on_generation) {
icon( "blank");
} else {
icon( "line");
}
}
if ($child_nodes[$node]) { // has children, i.e. it is a folder
$conn_icon = "plus";
$expand = true;
} else {
$conn_icon = "join";
$expand = false;
}
if ($index == $lastindex) {
$conn_icon .= "bottom";
} elseif ($depth == 0 && $index == 0) {
$conn_icon .= "top";
}
if ($expand) {
printf( "<a href=\"javascript:document.layers['node_%d'].visibility='show'\">", $node);
}
icon($conn_icon, "connImg_$node");
if ($expand) {
print( "</a>");
}
$icon = $node_data[$node][ 'icon'];
if (!$icon) {
$type = $node_data[$node][ 'type'];
$icon = $GLOBALS[ 'dirent_icons'][$type];
}
icon($icon, "nodeImg_$node");

$name = $node_data[$node][ 'name'];
printf( '<font size="%d">%s</font><br%c>', -1, $name, 10);
if ($child_nodes[$node]) {
$newdepth = $showdepth;
if ($newdepth > 0) {
$newdepth--;
}
$new_ancestors = $ancestors;
$new_ancestors[] = $node;
display_directory($node, $newdepth, $new_ancestors);
}
}
print( "</div\n>");
}

function setup_directory($parent, $maxdepth)
{
global $dirent_icons, $child_nodes, $node_data, $last_child;

$dirent_icons = sql_assoc( 'SELECT id,icon FROM dirent_types');

$query = 'SELECT id,parent,type,icon,name '.
'FROM directory '.
'ORDER BY parent,name';

$child_nodes = array();
$node_data = array();
$res = sql($query);
while (list($id, $parent, $type, $icon, $name) = db_fetch_row($res)) {
$child_nodes[(int)$parent][] = $id;
$node_data[$id] = array( 'id' => $id,
'parent' => $parent,
'type' => $type,
'icon' => $icon,
'name' => $name);
$last_child[(int)$parent] = $id;
}
}

?>



Function to convert Arabic numbers into Roman Numerals
Categories : Algorithms, PHP, Date Time
How to Generate a random 8 character string in php3?
Categories : PHP, Algorithms
Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math.
Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers.
Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
Dollar Serial Number Validator
Categories : PHP, Security, Algorithms
what salt do I have to feed the crypt function with to make it work like the htpasswd command of apache?
Categories : Algorithms, PHP, Authentication
Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users).
Categories : Algorithms, Email, PHP
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
The Porter Word Stemming Algorithm in PHP Reduces words to their base stem for search engines and indexing
Categories : Algorithms, PHP, Strings
A recursive function to traverse a multi-dimensional array where the dimensions are not known
Categories : Arrays, PHP, Algorithms
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array.
Categories : Algorithms, Arrays, PHP, Complete Programs
How to validate an Israeli ID number.
Categories : Ecommerce, PHP, Algorithms
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects.
Categories : PHP, PHP Classes, Algorithms