Switch to english
Pages Pro
GPL Softwares
Musique & Démos
Perso & Photos
GPL home
 GPL softwares home
Domain Technologie Control
 DTC : a web interface for controling your domain name.
 J'upload : the ultimage JAVA upload applet for your web site.
 Fashion : an interface builder written in 68030 assembly for Atari and compatibles.
PHP Functions
Tree Mem2DB lib : this small script enable transfer in both ways from memory to a MySql database of a PHP tree stored with arrays of arrays.
Multipurpose and very usefull, you'll be allowed to store any attributes you need for all nodes.
 User support
PHP libs and functions
PHP Libs

Some very usefull functions for your own PHP code !
Multi-purpose tree storage using MySql

Multi purpose tree Memory <-> Database library

I've often used some "tree" representation using PHP's multidimentional arrays. This is very usefull, but you get stopped when you need to save (or load) that tree in a MySQL database. This small script (16 KB) tends to solve that problem using some references from one record to another.

Imagine you have the following tree to be saved :
$tree = array(
		"text" => "Corporate / Investors",
		"arbo" => "compinfo",
		"childrens" => array(
				"text" => "Background / profiles",
				"arbo" => "background",
				"text" => "Shareholders",
				"arbo" => "shares",
which for example, will represent the navigation menu you need to use. If you need to save that in your databases, you only need to call TMDtreeMemToDB($treeID,$tree); and it will be saved to your database.

For each type of tree, you will need 2 tables, one for indexing your trees using names, and one that will store all the trees informations. Please note that each field you add to the table will be understood by the lib and will be returned as a node attribute.

Here is the SQL code for creating the tables. Note that "text" and "arbo" are only example of fields that are returned as your nodes attributes.
# Create the tree-index table

CREATE TABLE treeindex (
  id int(11) NOT NULL auto_increment,
  name varchar(32) NOT NULL default '',
  root_object_id int(11) NOT NULL default '0',
  PRIMARY KEY  (id),
  FULLTEXT KEY name (name)

# Create the tree table (more than one tree can be stored here,
# but all the indexes can change when saving back to SQL)

CREATE TABLE alltreenodes (
  id int(11) NOT NULL auto_increment,
  ob_head int(11) NOT NULL default '0',
  ob_tail int(11) NOT NULL default '0',
  ob_next int(11) NOT NULL default '0',
  tree_id int(11) NOT NULL default '0',
  arbo varchar(32) NOT NULL default '',
  text varchar(64) NOT NULL default '',
With this example, you can use the following code to retrive your data from MySQL :
mysql_connect( [... some params you should know ...] );
$tree_id = TMDgetTreeID("thename_of_my_tree");
Finaly, here is the code available for download. This new version (19th of march) correct a bug in the newTree() function that was destroying some other trees because of a malformed WHERE close. My appologies for that bug.


seek - Xen VPS hosting