I am trying to build a 3 coloumn list of all categories listed alphabetically. I was building my categories by ID and the following global worked fine, I am now building based on categories and need some help with the output....
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","sm_graphic"] );
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 $output = qq|<table width="100%" border=0><tr><td width="$width%" valign="top"><tr><td valign="top">\n|;
while ($row = $sth->fetchrow_hashref) {
$letter = uc(substr($row->{Name}, 0, 1));
if ($letter !~ /$oldletter/i ){
$output .= qq|<P><font face="Arial"><b><a name="$letter">$letter</a></b></font></P>\n|;
$oldletter = $letter;
}
$output .= qq|<font face="Arial" size="2"><a href="$CFG->{build_root_url}/$row->{ID}">$row->{Name}</a></font><br>\n|;
($i > 0) and !($i % $breakpoint) and ($output .= qq|</td>\n<td valign="top" width="$width%">\n|);
$i++;
}
$output .= "</td></tr></table></font>\n";
return $output;
}
Thanks....
George
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","sm_graphic"] );
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 $output = qq|<table width="100%" border=0><tr><td width="$width%" valign="top"><tr><td valign="top">\n|;
while ($row = $sth->fetchrow_hashref) {
$letter = uc(substr($row->{Name}, 0, 1));
if ($letter !~ /$oldletter/i ){
$output .= qq|<P><font face="Arial"><b><a name="$letter">$letter</a></b></font></P>\n|;
$oldletter = $letter;
}
$output .= qq|<font face="Arial" size="2"><a href="$CFG->{build_root_url}/$row->{ID}">$row->{Name}</a></font><br>\n|;
($i > 0) and !($i % $breakpoint) and ($output .= qq|</td>\n<td valign="top" width="$width%">\n|);
$i++;
}
$output .= "</td></tr></table></font>\n";
return $output;
}
Thanks....
George