This code do this:
- now the group letters are big
- both small and capital letters are listed in same group
- I did not corrected the bug, which causes not split into 3 columns
(I should execute the script to correct it. You have to correct this.)
- it is not possible so easily to merge the groups 0-9 into one. It is only possible if you do an exception, and you treat numbers separately.
Try this:
my ($db, $sth, $row, $oldletter, $letter, $i);
my $output="";
$db = $DB->table('Category');
$db->select_options("ORDER BY Name");
$sth = $db->select( ['ID','Name'] );
my $cols = 3;
my $row_count = $sth->rows;
my $breakpoint = int (($row_count) / $cols) + ( (($row_count) % $cols) ? 1 : 0);
my $width = int (100 / $cols);
my $table = qq|<table><tr><td width="$width%" valign="top">\n|;
while ($row = $sth->fetchrow_hashref) {
$letter = uc(substr($row->{Name}, 0, 1));
if ($letter =~ /^$oldletter.*/i ){
$output .= qq|<b>$letter</b><br>\n|;
$oldletter = $letter;
}
$output .= qq|<br><a href="$CFG->{build_root_url}/$row->{ID}">$row->{Name}</a>\n|;
($i > 0) and !($i % $breakpoint) and ($output .= qq|</td>\n<td valign="top" width="$width%">\n|);
$i++;
}
$output .= "</td></tr></table>\n";
return $output;
}
You got the starting steps help, so I think you should finish yourself.
If you still have problems, post it here, and you may get the help.
Best regards,
Webmaster33
Paid Support from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
- now the group letters are big
- both small and capital letters are listed in same group
- I did not corrected the bug, which causes not split into 3 columns
(I should execute the script to correct it. You have to correct this.)
- it is not possible so easily to merge the groups 0-9 into one. It is only possible if you do an exception, and you treat numbers separately.
Try this:
Code:
sub { my ($db, $sth, $row, $oldletter, $letter, $i);
my $output="";
$db = $DB->table('Category');
$db->select_options("ORDER BY Name");
$sth = $db->select( ['ID','Name'] );
my $cols = 3;
my $row_count = $sth->rows;
my $breakpoint = int (($row_count) / $cols) + ( (($row_count) % $cols) ? 1 : 0);
my $width = int (100 / $cols);
my $table = qq|<table><tr><td width="$width%" valign="top">\n|;
while ($row = $sth->fetchrow_hashref) {
$letter = uc(substr($row->{Name}, 0, 1));
if ($letter =~ /^$oldletter.*/i ){
$output .= qq|<b>$letter</b><br>\n|;
$oldletter = $letter;
}
$output .= qq|<br><a href="$CFG->{build_root_url}/$row->{ID}">$row->{Name}</a>\n|;
($i > 0) and !($i % $breakpoint) and ($output .= qq|</td>\n<td valign="top" width="$width%">\n|);
$i++;
}
$output .= "</td></tr></table>\n";
return $output;
}
You got the starting steps help, so I think you should finish yourself.
If you still have problems, post it here, and you may get the help.
Best regards,
Webmaster33
Paid Support from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...