Hi all,
I'm looking to create a table where I can
pass alterations to an SQL statement.
Say I have a form returned to me and at the top
of each column is a button with the column name.
If I click on a button, the SQL statement gets
altered and the results are reverse-sorted.
This is what I have so far:
use strict;
my ($order_by,$sql,$asc_desc);
$sql = qq{SELECT * FROM TABLE};
$order_by = param('order_by');
$asc_desc = param('asc_desc');
if (defined($order_by)) {
if ($asc_desc eq 'ASC') {
$sql .= " ORDER BY $order_by ASC ";
}
else {
$sql .= " ORDER BY $order_by DESC ";
}
}
print header,
start_html(),
start_form(),
center(
p($order_by),
start_table(),
Tr(td(submit('order_by','FAULT_NO',)),
td(submit('order_by','ISSUE')),
td(submit('order_by','RESPONSE'))),
end_table(),
hidden('order_by',$order_by),
hidden('asc_desc',$asc_desc),
p($sql),
),
end_form(),
end_html();
exit;
Don't worry about column name generation for now...
Now the default SQL is 'SELECT * FROM TABLE'
and when I press the 'FAULT_NO' button,
the SQL statement becomes 'SELECT * FROM TABLE
ORDER BY FAULT_NO DESC'. Similar results for
the other buttons. Looks like I have the table
column changing as it should, but I'm having a
bugger of a time trying to get the 'ORDER BY'
bit to change from DESC (take as default)
to ASC... A little help please? Many thanks,
Stacy.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.