My suggestions are:
- Reuse your database connection rather than disconnecting and reconnecting.
- As described in DBI, you shouldn't need to use $sth->finish().
- You're single-quoting your query and simultaneously trying to get perl to substitute $concordance, which won't work. Change your quoting method.
- I'm not knowledgeable about mySQL, but I don't see how you're going to switch between pages. I would think that you'd need a sortable key column (that you don't have to show the user) so you can tell mySQL where to begin the SELECT in order to page through it.
To illustrate the last point, here's what I mean. Suppose you have the table:
create table Names (
the_key int PRIMARY KEY,
last_name varchar(32),
first_name varchar(32)
)
Now if you want to present the names, you might have a bit of code something like:
# Setup code
my $SortField = 'last_name'; # could be 'first_name'
my $Page = '';
my $PageSize = 50;
<<SNIP SNIP SNIP SNIP SNIP>>
# Get the page of data
my $SQL = "SELECT first_name, last_name "
. "FROM Names "
. "WHERE $SortField >= '$Page' "
. "ORDER BY $SortField "
. "LIMIT $PageSize ";
my $results = $db->selectall_arrayref($SQL);
Then in your code, when the person hits the NEXT PAGE button, you simply set $Page to the value of the last $SortField value in your current page. (To move in reverse, have mySQL sort the data in reverse and use the same logic. But after you get your results, reverse the results array so you don't confuse your user.
...roboticus
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.