Two ways to do the same thing, I'd like your feedback on them please. It's
my first experience for an interactive webpage with a DB..

# This method (fetchall):

my $res = $dbh->selectall_arrayref("SELECT right(left(evtDtSt,10),2),
evtName from events order by evtDtSt");
for (1..31) # for the 31 days of the month
{ print "$_<br>";
   while ((defined (@{$res})) && (@{$res}[0]->[0] == $_)) # as long as the
date is the first event of the result's date
   { print "@{$res}[0]->[1]<br>"; # print the event's name
      shift @{$res}; # go to the nest one...
   }
}

# Or this method (fetchrow):

my $sth = $dbh->prepare("SELECT right(left(evtDtSt,10),2), evtName from
events order by evtDtSt");
$sth->execute();
my $i = 1;
while (my @event = $sth->fetchrow_array()) # as long as we have events left
{ while ($i<=@event[0]) # prints the date as long as we're not at the first
event's date
  { print "$i<br>";
     $i++;
   }
   print "@event[1]<br>"; # then we print the event's name
}
while ($i<=31) # to finish the month
{ print "$i<br>";
   $i++;
}

#####

Ok, both methods gives the same result...
For my calendar, when I include this into the print of the dates, I was able
to do it with the fetchall, but I dunno if I would be able to get it to work
ok with the fetchrow..

Anyways, I'd like to know which method you recommend and why.. or if both
methods are equivalent.

Etienne

Reply via email to