<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hey,<div class=""><br class=""></div><div class="">I’m using hash and sorting it from the template toolkit.</div><div class="">I would advise to try it then later you can play with the speed.</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Attila</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 26 Aug 2015, at 19:39, Richard Reina <<a href="mailto:gatorreina@gmail.com" class="">gatorreina@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="">Andrew and Attilla,<br class=""><br class=""></div>Thank you for the replies.  I am guessing that keeping the sorting in the SQL instead of the HTML would mean the page would load faster so I trying to go that route.<br class=""> <br class=""></div><div class="">However, when I switch my code above to:<br class=""></div><br class="">    <% FOREACH job in Jobs %><br class="">        <option value="<% job.ID %>"><% Job.NAME %></option><br class="">        <% END %><br class=""><div class="gmail_extra"><br class=""></div><div class="gmail_extra">I get an empty dropdown. I am using $sth->fetchall_arrayref(); with no arguments. Sorry to ask, but been playing with it for over an hour and still have it figured it out.<br class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2015-08-26 9:04 GMT-05:00 Andrew Beverley <span dir="ltr" class=""><<a href="mailto:andy@andybev.com" target="_blank" class="">andy@andybev.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Wed, 2015-08-26 at 08:51 -0500, Richard Reina wrote:<br class="">
> I have this table data that I load into a template as follows.<br class="">
><br class="">
>   $q = "SELECT ID, NAME<br class="">
>                 FROM jobs<br class="">
>                 ORDER BY NAME";<br class="">
>        $sth = $dbh->prepare($q);<br class="">
>        $sth->execute();<br class="">
>        my $Jobs_ref = $sth->fetchall_hashref('ID');<br class="">
<br class="">
</span>use fetchall_arrayref() instead.<br class="">
<span class=""><br class="">
> To display it in the template as a drop-down select I do:<br class="">
><br class="">
>     <select class="selectpicker" name="jobselect" id="jobselect"<br class="">
> style="width: 500px;"><br class="">
>               <% FOREACH ID IN Jobs.keys %><br class="">
<br class="">
</span>Here you just need something like<br class="">
<br class="">
    FOREACH job in Jobs<br class="">
<span class=""><br class="">
>         <option value="<% Jobs.$<a href="http://id.id/" rel="noreferrer" target="_blank" class="">ID.ID</a> %>"><% Jobs.$<a href="http://id.name/" rel="noreferrer" target="_blank" class="">ID.NAME</a> %></option><br class="">
<br class="">
</span>And then here use job.ID, job.NAME etc.<br class="">
<span class=""><br class="">
> And it works great. Except for one thing, the list is not in order by name.<br class="">
> I have read more than a few posts about how once you save a query as a<br class="">
> hashref that the order is lost.<br class="">
<br class="">
</span>Yes, in Perl arrays are ordered, hashes are not. If you want to retain order, you<br class="">
must use an array (or sort the hash before use, which is expensive).<br class="">
<span class=""><br class="">
>  Most of those posts suggested fetching as a<br class="">
> arrayref instead. However, I have no idea how to do that and then display<br class="">
> it in a select like the above code does.<br class="">
<br class="">
</span>See above.<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
dancer-users mailing list<br class="">
<a href="mailto:dancer-users@dancer.pm" class="">dancer-users@dancer.pm</a><br class="">
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank" class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br class="">
</blockquote></div><br class=""></div></div>
_______________________________________________<br class="">dancer-users mailing list<br class=""><a href="mailto:dancer-users@dancer.pm" class="">dancer-users@dancer.pm</a><br class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users<br class=""></div></blockquote></div><br class=""></div></body></html>