<div dir="ltr"><div><div>Andrew and Attilla,<br><br></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> <br></div><div>However, when I switch my code above to:<br></div><br> <% FOREACH job in Jobs %><br> <option value="<% job.ID %>"><% Job.NAME %></option><br> <% END %><br><div class="gmail_extra"><br></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><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-26 9:04 GMT-05:00 Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span>:<br><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>
> I have this table data that I load into a template as follows.<br>
><br>
> $q = "SELECT ID, NAME<br>
> FROM jobs<br>
> ORDER BY NAME";<br>
> $sth = $dbh->prepare($q);<br>
> $sth->execute();<br>
> my $Jobs_ref = $sth->fetchall_hashref('ID');<br>
<br>
</span>use fetchall_arrayref() instead.<br>
<span class=""><br>
> To display it in the template as a drop-down select I do:<br>
><br>
> <select class="selectpicker" name="jobselect" id="jobselect"<br>
> style="width: 500px;"><br>
> <% FOREACH ID IN Jobs.keys %><br>
<br>
</span>Here you just need something like<br>
<br>
FOREACH job in Jobs<br>
<span class=""><br>
> <option value="<% Jobs.$<a href="http://ID.ID" rel="noreferrer" target="_blank">ID.ID</a> %>"><% Jobs.$<a href="http://ID.NAME" rel="noreferrer" target="_blank">ID.NAME</a> %></option><br>
<br>
</span>And then here use job.ID, job.NAME etc.<br>
<span class=""><br>
> And it works great. Except for one thing, the list is not in order by name.<br>
> I have read more than a few posts about how once you save a query as a<br>
> hashref that the order is lost.<br>
<br>
</span>Yes, in Perl arrays are ordered, hashes are not. If you want to retain order, you<br>
must use an array (or sort the hash before use, which is expensive).<br>
<span class=""><br>
> Most of those posts suggested fetching as a<br>
> arrayref instead. However, I have no idea how to do that and then display<br>
> it in a select like the above code does.<br>
<br>
</span>See above.<br>
<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</blockquote></div><br></div></div>