This is how I deal with user-defined sort orders, which I (personally) think is a little more readable. . .This is taken straight from production code. . .Plus, to add more sorts you only need to add them to the drop-down and the hash.
my %sorts=(
form=>'form_list.form_title',
rform=>'form_list.form_title desc',
name=>'stored_forms.client_name',
rname=>'stored_forms.client_name desc',
prepared=>'stored_forms.advocate_name',
rprepared=>'stored_forms.advocate_name desc',
date=>'stored_forms.created',
rdate=>'stored_forms.created desc'
);
my $sort=$sorts{$q->param('sort')} || $sorts{'form'};
my $forms=$dbh->prepare("select stored_forms.client_name, form_lis
+t.form_title, stored_forms.id,
stored_forms.advocate_name,date_format(stored_forms.created,'%c/%e/%Y'
+) as save_date,
stored_forms.client_accountnum,form_list.form_location
from form_list, stored_forms
where form_list.form_type = stored_forms.form_type and
stored_forms.client_accountnum like ?
order by stored_forms.client_accountnum,".$sort);
HTH
-Any sufficiently advanced technology is
indistinguishable from doubletalk.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.