Problems using Tree - DBsimple!
| From: | Tommy Ipsen | Date: | Mon, 03 Nov 2003 17:35:01 +0000 |
| Subject: | Problems using Tree - DBsimple! | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-8735@lists.php.net to get a copy of this message | ||
Hi group
I have the following code:
------------------------------------------------------------------
require_once 'Tree/Tree.php';
// setup a memory tree using nested sets
$tree = Tree::setup('Memory_DBsimple', $db, array('table' => 'menu', 'order' => 'priority', 'columnNameMaps' => array('parentId' => 'parentId', 'name' => 'title'), 'whereAddOn' => ''));
// read the data from the DB and build the tree internally
$tree->setup();
$tree->varDump();
print_r($tree->data);
------------------------------------------------------------------
And the following db-structure:
------------------------------------------------------------------
CREATE TABLE menu (
id int(10) unsigned NOT NULL auto_increment,
parentId int(10) unsigned default NULL,
priority smallint(6) NOT NULL default '0',
title varchar(255) NOT NULL default '',
PRIMARY KEY (id),
KEY pid (parentId)
) TYPE=MyISAM COMMENT='Tree based menu system';
#
# Data dump for tabellen
menu
#
INSERT INTO menu VALUES (1, 0, 0, 'Personal');
INSERT INTO menu VALUES (2, 1, 0, 'Study');
INSERT INTO menu VALUES (3, 1, 1, 'Guestbook');
------------------------------------------------------------------
Unfortunately my use of the Tree class doesn't seem to work properly - I get the following output from the above-code:
------------------------------------------------------------------
Warning: Invalid argument supplied for foreach() in z:\php\pear\Tree\Memory.php on line 1276
Warning: Invalid argument supplied for foreach() in z:\php\pear\Tree\Memory.php on line 1284
Array ( [1] => Array ( [id] => 1 [priority] => 0 [name] => Personal [nextId] => 2 [next] => Array ( [id] => 2 [priority] => 0 [name] => Study [prevId] => 1 [previous] => Array *RECURSION* [nextId] => 3 [next] => Array ( [id] => 3 [priority] => 1 [name] => Guestbook [prevId] => 2 [previous] => Array *RECURSION* ) ) ) [2] => Array ( [id] => 2 [priority] => 0 [name] => Study [prevId] => 1 [previous] => Array ( [id] => 1 [priority] => 0 [name] => Personal [nextId] => 2 [next] => Array *RECURSION* ) [nextId] => 3 [next] => Array ( [id] => 3 [priority] => 1 [name] => Guestbook [prevId] => 2 [previous] => Array *RECURSION* ) ) [3] => Array ( [id] => 3 [priority] => 1 [name] => Guestbook [prevId] => 2 [previous] => Array ( [id] => 2 [priority] => 0 [name] => Study [prevId] => 1 [previous] => Array ( [id] => 1 [priority] => 0 [name] => Personal [nextId] => 2 [next] => Array *RECURSION* ) [nextId] => 3 [next] => Array *RECURSION* ) ) [] => )
------------------------------------------------------------------
How come it doesn't work... :-/ - Apparently the records are read from the database but not processed correctly - any ideas?
Hope you can help me out here!
Cheers,
Tommy Ipsen