Ok, for anyone following this thread, I got the recursive function to
work, I will paste the source here.  I could not declare it as an
embperl sub, I had to declare it as a normal perl sub within an
embperl block in the same file as I am using it.  I tried about every
other iteration without success.  Thanks to Gerald for your help, 
if you can think of a better way to do this  (namely one that lets me
write the html without extra \'s and perl print OUT statements) I'd
love to hear it.  Thanks again for making the tool that takes the 
drudgery out of making forms and HTML.

The only other real option would have been to jump to 2.0,
and I don't particularly want to do that before migrating to apache 2.  

Anyway, here be the code:

[- 
   $dsn = 'your:info:goes:here';
   $user = 'user';
   $pass = 'pass';
   %attr = ( PrintError => 1, RaiseError => 0 );
   $dbh = DBI->connect ( $dsn, $user, $pass, \%attr );

sub printTree {

 my ($parent, $depth) = (0, 0);
    ($parent, $depth) = @_ if (defined (@_));

 # might want to add some sanity checks here on the input..

 my $sth = $dbh->prepare( "select id, data, child_of, item_number from to_do where 
child_of = '$parent' order by item_number" );
    $sth->execute();

 while( my ($child, $data, $child_of, $item_number) = $sth->fetchrow_array() ) {

   print OUT "\<tr>\<td>";
   print OUT "-- " x $depth;
   print OUT "$item_number : $data \</tr>\</td>";

   my $sth = $dbh->prepare( "select count(*) from to_do where child_of = '$child'" );
      $sth->execute();
   my ($children) = $sth->fetchrow_array();

   printTree($child, $depth+1) if $children;
 }

}

-]

  <table border="0">
   [- printTree -] 
  </table>

__END_EMBPERL__

That is to accompany a db table such with at least these columns:

+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| id          | int(11)     |      | PRI | NULL    | auto_increment |
| child_of    | int(11)     |      |     | 0       |                |
| item_number | int(11)     | YES  |     | NULL    |                |
| data        | blob        |      |     |         |                |
+-------------+-------------+------+-----+---------+----------------+



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to