Subject Re: PDO
Author darren_pwrs
OK yes the line number was repported with the error and I don't know
why the make a double var but it was in the original code i used. If i
do a var dump of $branch_parent and $$branch_parent i get the same
result "int(198)". I commented out this part of the original code: /*
> >> $branch = $db->f("ID");
> >> $branch_parent = $db->f("ParentId");
> >> $branch_value = $db->f("Name");*/

bellow is the original code:

// Build a TreeView from a database.
// Interface phpguru.com's TreeMenu to CCS.
http://www.phpguru.org/static/treemenu.html
// 5-18-05 jnorris

// DB table requires a branch, parent_branch, and contents columns.
// I'm also filtering by UserID for my application. Adjust as necessary.

// Get UserID for use with query...
$UserID = CCGetFromGet("UserID",0);

if($UserID > 0) {

require_once('./TreeMenu.php');

$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
$i = 0; //index

// connect to DB...
$db = new clsDBConnection1();
$SQL = "SELECT * FROM box WHERE box_client_id = ".$UserID;

$db->query($SQL);
$Result = $db->next_record();

$menu = new HTML_TreeMenu();

while($Result > 0) {

// populate variables from db...
$branch = $db->f("box_compartment");
$branch_parent = $db->f("box_parent_compartment");
$branch_value = $db->f("box_value");

// Build tree...
if($branch_parent) {
$$branch = &$$branch_parent->addItem(new HTML_TreeNode(array('text' =>
$branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon' =>
$expandedIcon)));
} else {
$$branch = new HTML_TreeNode(array('text' => $branch, 'link' =>
$branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon));
$tree[$i++] = &$$branch; // Indexed reference for final tree consruction.
}

unset($branch);
unset($branch_parent);
unset($branch_value);

$Result = $db->next_record();
} //wend

$db->close();


// FOREACH was uncooperative for some reason...
$temp = 0;
while($temp < $i){
$menu->addItem($tree[$temp]);
$temp++;
}

// Stuff menu DHTML into the label...
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' =>
'./images', 'defaultClass' => 'treeMenuDefault'));
$Label_TreeMenu->SetValue($treeMenu->toHTML());

} else { // Error message stuffed into label instead...
$Label_TreeMenu->SetValue("TREEMENU: No UserID");
} //endif


Thanks Again



--- In firebird-php@yahoogroups.com, Jochem Maas <jochem@i...> wrote:
> Alan McDonald wrote:
> >>Ok got PHP_intebase working and am now working on generating a
> >>html_TreeMenu from a database query.
> >>
> >>I'm using HTML_TreeMenu and loopping through my results but i keep
> >>getting this message "Call to a member function addItem() on a
> >>non-object". I have done hardly any OOP but I think the problem is
> >>somewhere in the this code:
>
> I assume the error is being reported with the line number of the
line that
> reads as:
>
> " $$branch = &$$branch_parent->addItem( " ... <etc>
>
> >>
> >>while($row = ibase_fetch_object($result)) {
> >> //print_r($Result);
> >> echo $row->Name .'<br>';
> >> echo 'Parent, '.$row->ParentId .'<br>';
> >> echo $row->ID .'<br>';
> >> // populate variables from db...
> >> $branch=$row->ID;
> >> $branch_parent = $row->ParentId;
> >> $branch_value = $row->Name;
> >> echo 'branch, '.$branch;
> >> /*
> >> $branch = $db->f("ID");
> >> $branch_parent = $db->f("ParentId");
> >> $branch_value = $db->f("Name");*/
> >>
> >> // Build tree...
> >> if($branch_parent) {
> >> $$branch_parent=$branch_parent;
> >> $$branch = &$$branch_parent->addItem(new
>
>
> what does var_dump($branch_parent, $$branch_parent) output?
>
> what does $db->f() do? does it return a field name, a field object?
> if its actually returning an object, what kind of object, and is this
> object in any way compatible with the HTML_TreeNode and HTML_Tree
classes?
>
> >>HTML_TreeNode(array('text'
> >>=> $branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon'
> >>=> $expandedIcon)));
> >> } else {
> >> $$branch = new HTML_TreeNode(array('text'
> >>=> $branch, 'link' =>
> >>$branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon));
> >> $tree[$i++] = &$$branch; // Indexed
> >>reference for final tree
> >>consruction.
> >> }
> >> //unset($branch);
> >> //unset($branch_parent);
> >> //unset($branch_value);
> >>
> >> //$Result = $db->next_record();
> >> } //wend
> >>
> >>thanks for all the help, some time even the smallest comments just
> >>seem to make things click.
> >>Darren
> >>
> >
> >
> > why $$branch? - 2 $ signs
>
> variable variables - not sure they are the best solution here
> ... although I have used var vars in similar tree buidling exercises.
>
> figure out what the following code is doing and you should be
> well on your way to grokking php var vars :-)
>
> <?php
>
> $var1 = "123"; $var2 = "var1";
> echo $$var2, "\n", ${"var1"}, "\n", ${${"var2"}}, "\n";
>
> ?>
>
> > Alan
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >