Listing 7: view-stories-form.html
%# -*- mmm-classes: mason -*-
View latest news
View latest news
<%once> my $dbh; %once>
<%init>
# Connect to the database, if we haven't already done so
$dbh = $m->comp("database-connect.comp");
# Get the list of categories
my $sql = "SELECT category_id, category_name ";
$sql .= "FROM Categories ";
$sql .= "ORDER BY category_name ";
my $sth = $dbh->prepare($sql);
$sth->execute;
my $row_ref;
my @categories;
# Put the list of categories into @categories
while ($row_ref = $sth->fetchrow_arrayref)
{
my ($id, $name) = @$row_ref;
push @categories, {id => $id,
name => $name};
}
%init>