Hi, I'm somewhat new at perl and just started playing with DBI this morning. I'm having a problem when looping through a recordset and executing a SELECT within the while loop which depends on a value from the first. It appears that on every iteration rows are being appended to $sth, but I want to empty $sth on every iteration and get a fresh recordset.
ex: first iteration returns:
1 foo
2 bar
next iteration is appending to first:
1 foo
2 bar
3 musty
4 tshirt
the second iteration should just return:
3 musty
4 tshirt
I've included the while loop below, thanks for any help.
while ( my ($intMemberID,$txtUsername,$txtPassword,$txtName,$txtEmail,
+$txtBio) = $rsMembers->fetchrow_array) {
my $sth = $dbh->prepare( "SELECT intSiteID,txtURL,txtTitle,txtDesc
+ription FROM Sites WHERE intMemberID = ? ORDER BY txtTitle" );
$sth->execute($intMemberID);
while ( my ($intSiteID,$txtURL,$txtTitle,$txtDescription) = $sth -
+>fetchrow_array) {
$websites.= load_template("member_site_index.tmpl", {sid => $i
+ntSiteID, url => $txtURL, title => $txtTitle, description => $txtDesc
+ription});
}
$sth ->finish;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.