CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



martinmb
New User

Aug 23, 2002, 9:13 AM

Post #1 of 3 (3815 views)
recursive query to make an xml tree? Can't Post

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

Post #2 of 3 (3807 views)
Re: [martinmb] recursive query to make an xml tree? [In reply to] Can't Post

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

Post #3 of 3 (3804 views)
Re: [thebitch] recursive query to make an xml tree? [In reply to] Can't Post

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

I shall use strict in future.

Thanks!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives