perlquestion
RickySilk
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.
<p>
ex: first iteration returns:<br>
1 foo<br>
2 bar<br>
<br>
next iteration is appending to first:<br>
1 foo<br>
2 bar<br>
3 musty<br>
4 tshirt<br>
<br>
the second iteration should just return:<br>
3 musty<br>
4 tshirt<br>
<br>
I've included the while loop below, thanks for any help.<br>
<CODE>
while ( my ($intMemberID,$txtUsername,$txtPassword,$txtName,$txtEmail,$txtBio) = $rsMembers->fetchrow_array) {
my $sth = $dbh->prepare( "SELECT intSiteID,txtURL,txtTitle,txtDescription 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 => $intSiteID, url => $txtURL, title => $txtTitle, description => $txtDescription});
}
$sth ->finish;
}
</CODE>