My code:
my $sql_query = "select Event_datetime,Event,User from logs";
my $sth = $dbh->prepare($sql_query);
$sth->execute();
$testResults = $sth->fetchall_arrayref();
foreach my $row (@$testResults) {
($Event_datetime,$Event,$User) = @$row;
print $query->h2($ID);
}
I would like to use a for loop to fetch the results of this query(once it is executed) such that each row has a number, i.e. since rows are listed sequentially, I need to access the row by its row number.
i.e. row 1 is 0; row 2 is 1; row 3 is 2 and so on...
for example:
for ($i=0; $i < $noOfRows; $i=$i+1) {
($ID,$Event_datetime,$Event,$User) = @$testResults;
print $query->h3($ID, ' ,', $Event_datetime, ',', $Event, ',', $User );
}
However, this query does not give me any output. How do I access a particular row by its row number ?
use strict;anduse warnings;to the top of your file. You are not showing a reproducible example.