The reason this doesnt do what you expect it to do is because you are
calling your function, which is then executing your SQL command and
returning the first recordset.
You are doing this over and over again - instead you should have some sort
of loop in your function that loops through ALL the recordsets. You could
put these recordsets into an array and return that array.
A simple example of this would be:
$recordcount = 0;
sub Comment() {
my( $sth, @comment );
$sth = $dbh->prepare("SELECT comment from dbtable
where comment = 'whatever'")
or die "Can't query comment: $DBI::errstr\n";
$sth->execute or die "Can't execute comment: $DBI::errstr\n";
while ($sth->fetchrow_array) {
$Comment[$recordcount] = $sth->fetchrow_array();
$recordcount ++;
}
return @Comment;
}
I havent tested this code - but I hope it helps to give you some idea why
your function doesnt quite do what you wanted it too.
>I'm trying to get a grip on functions.
>I want to connect to a database, execute a SELECT statement, and print
>each line where the criteria is met.
>
>This does what I want.
>
>my $comment;
>
> while ( $comment = $sth->fetchrow_array) {
> print "$comment\n";
> }
>===================================================
>
>This is my function attempting to do the same thing(?).
>
>sub Comment() {
>
> my( $sth );
>
> $sth = $dbh->prepare("SELECT comment from dbtable
> where comment = 'whatever'")
> or die "Can't query comment: $DBI::errstr\n";
> $sth->execute
> or die "Can't execute comment: $DBI::errstr\n";
> return $sth->fetchrow_array();
>}
>===================================================
>
>When I call the function like this it prints the first line over and
>over, never getting the next line.
>
>my $comment;
>
> while ( $comment = Functions::Comment() ) {
> print "$comment\n";
> }
>====================================================
>
>I'm missing how the function is different from the original, or I
>am not understanding 'return'.
>
>
>--
>Charlie Farinella
>[EMAIL PROTECTED]
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
You are just a dewdrop, and as you meditate the dewdrop starts slipping from
the petals of the Lotus towards the ocean. When the meditation is complete,
the dewdrop has disappeared into the ocean. Or you can say, the ocean has
disappeared into the dewdrop.
Bhagwan Shree Rajneesh.
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]