I won't claim this is the best way to do it, but it's a
way to do it. Update: I recommend you
look at one of the other solutions.
Query the database, and put all the data in an array (I
would probably make each element of the array a struct
which contains all the data on a particular record).
Then you can simply keep track of your location in the
array (1, 49, 99, etc) and make a previous link which passes
the current location -50 (if applicable) and a next link
which passes the current location +50 (again, if this
doesn't exceed the limits of the array). Run a loop that
prints out all array entries between your current starting
point and 50 more (or the end of the array, whichever comes
first). Of course you need to make sure that the information
in the array is available to the instance or program that
prints it.
One possible problem with this approach is that your array
could contain outdated information if the database is
changed frequently. You could re-query the database, but
that could mess up the order, unless you are ordering by
a sequencial key.
| [reply] |
If you look three nodes down the line you'll find that this questioned has been answered, albeit, using slightly different terminology. Very good replies, and ideas of what not to do also...
#!/home/bbq/bin/perl
# Trust no1!
| [reply] |
The question is : what kind of db?
SELECT * FROM guests ORDER BY time DESC LIMIT 50
This is the sql line that's used for getting the first 50
In cgi I would make from 50 a variable so if somebody's pushes next(50) the variable would add 50.
Don't know how it's just done in perl. But I connected to the db with php to get what you wanted.
The best hint I can give is. Search on CPAN for DBI. Look to the perl-syntax how to connect to a db.
But most important is to know sql-syntax. Only then you can learn how to program databases(in any programming language).
--
My opinions may have changed,
but not the fact that I am right
| [reply] |
Look at the HTML::Embperl and DBIx::Recordset modules. The former will automatically generate HTML tables for your data (among many other things) and the latter provides a very simple way to access the results of your search in chunks of the size you need.
A really cool thing of using these modules is that the NEXT and PREVIOUS buttons are generated automatically depending of what chunk of your dataset you're browsing.
Check out the Embperl site for usage examples on both modules. | [reply] |