Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The intent of your recursive function is "find every immediate child of the specified parentId, print it as an option element, immediately followed by all of its children, etc." There are two issues with your code breaking this:
  1. Your method is handling two levels per invocation, instead of just one.
  2. The recursive call to your function is passing the current element's parentid, not the id. (Remember, "immediate child of the specified/current element.")
This should help:
# my super recurse the tree function, takes 2 options being parentid, +and current level sub recurQuery { my ($myParentId,$level) = @_; my $data = "SELECT id, parentid, catname from categories WHERE par +entid = ?"; my $sth = $dbh->prepare($data); $sth->execute($myParentId) or die $dbh->errstr; my $indent = '&nbsp;*' x $level; # loop through results while (my ($id,$parentid,$catname) = $sth->fetchrow_array()) { # print the beginning of the option box print"<option name='$catname'>$indent$catname</option>\n"; recurQuery( $id, $level + 1 ); } }
pg

In reply to Re: Possible loop problems in database query by pgor
in thread Possible loop problems in database query by coldfingertips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-01-18 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (54 votes). Check out past polls.

    Notices?