SPUG: Looping problem

Susanne Bullo sweetsue at sweethomes.com
Sat Jan 12 11:24:20 CST 2002


Ok, so my initial problem is all figured out.  Now, I believe I need a loop
inside of this:

  my $dbh = DBI->connect("DBI:mysql:$database", $username, $password) || die
"Failed DBI connect(): $!\n";
  my $query = "SELECT safelists.email_to, safelists.username,
safelists.password, email_txt.email_subject, email_txt.email_text,
safelists.uid, members.email from safelists, schedule, email_txt, members
where email_txt.id = schedule.SAT and schedule.system_name =
safelists.system_name and members.id = safelists.uid and
email_txt.email_subject != ''";

  $buffer .= "===> Executing Query: $query\n\n";
  my $sth = $dbh->prepare($query);
  my $rc = $sth->execute();

  while
(my($email_to,$username,$password,$email_subject,$email_text,$system_name,$u
id,$email) = $sth->fetchrow_array) {
  my $url = "http://$email_to?action=Send This
Message&username=$username&password=$password&subject=$email_subject&message
=$email_text";
  $email_text =~ s/\\//g;
  my $req = HTTP::Request->new(GET=>$url);
  my $file_path = "members/data/$username/$system_name/$date3.txt";
  my $resp = $ua->request($req, $file_path);
  my $sec_file_path = "members/data/$username";
  my $outfile = "index.html";
  my $filename = $sec_file_path/$outfile;
  open (FILE,">>$filename");
  print FILE "<a href=$sec_file_path target=_blank>Problem on $date3</a>";
  close (FILE);
  }
I need a loop that will take all $system_name variables that are returned
and cycle through them.  I have found this:

Perl While Loop Example

If your SQL query will return more than one record, you will need to place
the fetchrow() call in a while loop.


my (@telephone);
my $i = 0;
my $count;
while (@aRow = $sth->fetchrow())
{
    $telephone[$i] = @aRow[0];
    $i++;
}
$count = $i;

# @telephone can now be used to build an html table
# to display all the telephone numbers in the "518"
# area code.
But it is a bit confusing as I'm not certain about the syntax.

Thanks for putting up with me!  One of these times I might be able to attend
a meeting - I have three small children at home and both myself and my
husband are work-a-holics so it's a bit difficult.

Susanne Bullo - Sweet Homes
DirectTV DSL
Get Paid to Read Email!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20020112/43fed255/attachment.htm


More information about the spug-list mailing list