I'm fairly new to Perl so please bear with me.
I have some code that does a select, bind those results, and continues fetching while there is more records. That works great, but after I get the first piece of data the runs my while loop I need to get more data depending of its value and assign it to variables. I'm not sure how to do this. Below is what I have tried, but it's obviously not working.
my $sth = $dbh->prepare("SELECT tblA.data1
FROM tblA WHERE tblA.data2='' AND
tblA.data3=$var1"
|| die $!;
$sth->execute();
$sth->bind_columns(undef, \$data1);
print header();
open(TEMPLATE, "file.htm"
|| die $!;
while (<TEMPLATE>) {
if ($data1 > 900) {
my $sth1 = $dbh->prepare("SELECT tblB.data2, tblB.data3, tblC.data1
FROM (tblD INNER JOIN tblB ON tblD.data1 = tblB.data1) INNER JOIN tblC ON
tblD.data2 = tblC.data2
WHERE (((tblB.data1)=$data1));
$sth1->execute();
$sth1->bind_columns(undef, \$data2, \$data3, \$data4);
$sth1->fetch();
}
else if($data1 < 900) {
my $sth1 = $dbh->prepare("SELECT tblB.data2, tblB.data3, tblC.data1
FROM (tblE INNER JOIN tblB ON tblE.data1 = tblB.data1)
INNER JOIN tblC ON
tblE.data2 = tblC.data2
WHERE (((tblB.data1)=$data1));
$sth1->execute();
$sth1->bind_columns(undef, \$data2, \$data3, \$data4);
$sth1->fetch();
}
.......................(mostly html)
while($sth->fetch()){
...............(mostly html)
Thanks in advance for any help.
Cheryl
I have some code that does a select, bind those results, and continues fetching while there is more records. That works great, but after I get the first piece of data the runs my while loop I need to get more data depending of its value and assign it to variables. I'm not sure how to do this. Below is what I have tried, but it's obviously not working.
my $sth = $dbh->prepare("SELECT tblA.data1
FROM tblA WHERE tblA.data2='' AND
tblA.data3=$var1"

$sth->execute();
$sth->bind_columns(undef, \$data1);
print header();
open(TEMPLATE, "file.htm"

while (<TEMPLATE>) {
if ($data1 > 900) {
my $sth1 = $dbh->prepare("SELECT tblB.data2, tblB.data3, tblC.data1
FROM (tblD INNER JOIN tblB ON tblD.data1 = tblB.data1) INNER JOIN tblC ON
tblD.data2 = tblC.data2
WHERE (((tblB.data1)=$data1));
$sth1->execute();
$sth1->bind_columns(undef, \$data2, \$data3, \$data4);
$sth1->fetch();
}
else if($data1 < 900) {
my $sth1 = $dbh->prepare("SELECT tblB.data2, tblB.data3, tblC.data1
FROM (tblE INNER JOIN tblB ON tblE.data1 = tblB.data1)
INNER JOIN tblC ON
tblE.data2 = tblC.data2
WHERE (((tblB.data1)=$data1));
$sth1->execute();
$sth1->bind_columns(undef, \$data2, \$data3, \$data4);
$sth1->fetch();
}
.......................(mostly html)
while($sth->fetch()){
...............(mostly html)
Thanks in advance for any help.
Cheryl