I feel your pain. I've
done that (search for "Mazda", say), and I could paste you the code, but really it would do more harm than good (I was slightly traumatized just reviewing it --
WHAT WAS I THINKING??? hehe :)
You want to do as Masem says and use COUNT(*)
(which is optimized in MySQL) to get the total number
of rows. Divide those into groups depending on the scale
of the results. I ended up doing this:
for (my $i=100; $i <= 1000; $i += 100) {
if ($num_matched <= $i) {
$rows = $i / 10;
last;
}
}
unless ($rows) {
for (my $i=2000; $i <= 10000; $i += 1000) {
if ($num_matched <= $i) {
$rows = $i / 10;
last;
}
}
}
$rows = 1000 if $num_matched > 10000;
Basically I had to play with it to get the number of results per page to be reasonable (if there are 50
results, then you want 1-10, 11-20, etc.., but then
if there are 500 results you might want 1-100, 101-200,
etc..).
Then the other main part is maintaining the "state" of
the search results. So, if they're on page 3, you have to know that corresponds to "LIMIT 21,30" in
the SQL, say. If you look at the link above, there is a
CGI param called "offset" for that.
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.