Hi everyone,
I have the following script:
my ($query) = our $connect->prepare("SELECT number, name FROM TableNam
+e");
$query->execute();
my $data = $query->fetchall_arrayref();
$query->finish;
foreach $data ( @$data) {
my %row_data; # get a fresh hash for the row data
my ($variable1, $variable2) = @$data;
$row_data{number} = "$variable1";
$row_data{name} = "$variable2";
}
push(@loop_data, \%row_data);
}
Not the most efficient way of doing this but achieves what I want.
I would like to be able to do a similar thing, but for an unknown number of columns in the SQL Table.
So:
my ($query) = our $connect->prepare("SELECT * FROM TableName");
$query->execute();
my $data = $query->fetchall_arrayref();
$query->finish;
foreach $data ( @$data) {
my %row_data; # get a fresh hash for the row data
foreach my $data_item (@$data) {
$row_data{NAMEOFSQLCOLUMN} = "$data_item"; # How do I get the name
+ of the SQL column that the data_item belong to?
}
}
push(@loop_data, \%row_data);
}
Any help would be very much appreciated!