Home: Perl Programming Help: DBI:
recursive query to make an xml tree?



martinmb
New User

Aug 23, 2002, 9:13 AM


Views: 7983
recursive query to make an xml tree?

Hi All!

I'm trying to work out how to do a recursive MySql query on a
table of forum messages to make an xml document.

In my messages table I have data fields for id, parent of the
message, child of the message and others for the subject, body,
time, etc...

The DBI 'while fetchrow_array()' loop seems to be stopping the recursion.

I am new to perl and DBI and have tried the few things I know to re-write it,

without any joy.

Please can you help or give me any pointers?

Many Thanks!

Martin


Code
  

&read_Messages(" WHERE parent = 0");



sub read_Messages{

$myWhere = "@_";

if (!($sth = $dbh->prepare("SELECT $mySelect FROM $myTable $myWhere"))) {
snip... execute etc

while (my ($id, $parent, $child, $body) = $sth->fetchrow_array()) {

... do stuff

if($child != 0){
&read_Messages(" WHERE id = $child");
}

}

}



thebitch
User

Aug 26, 2002, 10:52 PM


Views: 7975
Re: [martinmb] recursive query to make an xml tree?

The only advice I can offer is

Code
use strict; 
use warnings;


after you have your code working under strict and warnings, see if it the fetchrow_array loop "stops"
the recursion, otherwise please provide more code


martinmb
New User

Aug 27, 2002, 6:46 AM


Views: 7972
Re: [thebitch] recursive query to make an xml tree?

Sorry for wasting space. it was a scoping error on $sth.

I shall use strict in future.

Thanks!