sub _dopsecArr {
my ($parent, $razdel) = @_ ;
my $items = $razdel->{$parent};
%items = %{ $items };
foreach my $n (keys %items ) {
@item = @{$items->{$n}};
$seclist .= qq[<option value='@item[0]'>@item[1]</option>];
_dopsecArr(@item[2], $razdel);
}
}
sub _dopsec {
$selectp = 'SELECT id, name, parent FROM razdel WHERE visible = 0 ORDER BY id';
my $sp = $dbh->prepare($selectp);
$sp->execute;
my $razdel;
while (@rp = $sp->fetchrow_array){
my $rp = \@rp;
push @{$razdel->{$rp[2]}->{$rp[0]}}, @rp;
}
$sp->finish;
_dopsecArr(0, $razdel);
}
sub _dopsecArr {
my ($parent, $razdel) = @_ ;
foreach my $n ({$razdel->{$parent}}){
$seclist .= qq[<option value='$n[0]'>$n[1]</option>];
_dopsecArr($n[2], $razdel);
}
}
while (@rp = $sp->fetchrow_array){
my $rp = \@rp;
push @{$razdel->{$rp[2]}}, @rp;
}
Array( 0 => array(
key1 => array(id, name, parent),
key2 => array(id, name, parent),
), 141 => array(
keyX => array(id, name, parent),
keyY => array(id, name, parent),
),
sub _dopsec {
$selectp = 'SELECT id, name, parent FROM razdel WHERE visible = 0 ORDER BY id';
my $sp = $dbh->prepare($selectp);
$sp->execute;
my @razdel;
while (@rp = $sp->fetchrow_array){
push @{$razdel->{$rp[2]}}, $rp;
}
_dopsecArr(0, $razdel);
$sp->finish;
}
sub _dopsecArr {
(my $razdel, my $arr) = @_ ;
foreach my $n (@{$arr->{$razdel}}){
$seclist .= qq[<option value='$n[0]'>$n[1]</option>];
_dopsecArr($n[2], $arr);
}
}
$comments = Db::getCommentsByArticle($id);
Кстати, id - уникальный ключ + инкримент возвращается без описания его в sql_field/attr.