[dancer-users] list order from a hash
Richard Reina
gatorreina at gmail.com
Wed Aug 26 14:51:05 BST 2015
I have this table data that I load into a template as follows.
$q = "SELECT ID, NAME
FROM jobs
ORDER BY NAME";
$sth = $dbh->prepare($q);
$sth->execute();
my $Jobs_ref = $sth->fetchall_hashref('ID');
template 'sport_add.tt', {
'Jobs' => $Jobs_ref,
'Testing' => "This is text to test to make sure this will come
through",
# to test, use this like <% Testing %> on your template page
}, {};
To display it in the template as a drop-down select I do:
<select class="selectpicker" name="jobselect" id="jobselect"
style="width: 500px;">
<% FOREACH ID IN Jobs.keys %>
<option value="<% Jobs.$ID.ID %>"><% Jobs.$ID.NAME %></option>
<% END %>
And it works great. Except for one thing, the list is not in order by name.
I have read more than a few posts about how once you save a query as a
hashref that the order is lost. Most of those posts suggested fetching as a
arrayref instead. However, I have no idea how to do that and then display
it in a select like the above code does. So I wanted to see if somebody
perhaps knows of a not too complicated of a solution to get the select list
into alphabetical order by name.
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150826/f14db245/attachment.html>
More information about the dancer-users
mailing list