sub get_thread_replies { my ($T_id, $M_id) = ($_[0], $_[1]); my $sth1 = $dbh->prepare("SELECT * FROM $vars{'poststable'} WHERE thre +ad_id = ? AND level_id = 0 AND parent_id = ? ORDER by message_id DESC +"); $sth1->execute($T_id, $M_id); $sth1->bind_col(1, \$message_id); $sth1->bind_col(2, \$parent_id); $sth1->bind_col(3, \$thread_id); $sth1->bind_col(4, \$level_id); $sth1->bind_col(5, \$name); $sth1->bind_col(6, \$email); $sth1->bind_col(7, \$location); $sth1->bind_col(8, \$icon); $sth1->bind_col(9, \$subject); $sth1->bind_col(10, \$body); $sth1->bind_col(11, \$message_url); $sth1->bind_col(12, \$message_url_title); $sth1->bind_col(13, \$datetime); $sth1->bind_col(14, \$user_icon); $sth1->bind_col(15, \$user_sig); $sth1->bind_col(16, \$reply_subject); while ( $sth1->fetch ) { print "<ul><li><b><a href=\"viewpost.cgi?thread_id=$thread_id&message_ +id=$message_id\">$subject</a></b> <img src=\"$vars{'boardiconsdirurl' +}/$icon.gif\" border=0> <b><font color=\"black\">$name</font></b> <s +mall><font color=\"dimgray\">$location </small> </font>$datetime\n"; &get_thread_replies($thread_id, $message_id); print "</ul>\n"; } }
The function recursively goes through the table looking for replies to a parent message, running the function again, until there are no more replies for that message id. I want to run the prepare statement however just once, and use execute thereafter, and not do what I am doing which is calling a prepare statement each time the function is called. Red------
In reply to Message Board Threading with DBI/MySQL by Red Neckerson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |