I'm showing a directory listing in one page now, but I want to show it in pages.

Currently I'm working like this:

gtsee.com/cgi-bin/nph-dirsub.pl?invoice=invoices/merchant_invoice_999999

and the script for showing the listings are:

my $sql=SELECT id, name, url FROM free_dirs;
my ( $id, $name, $url) = @{$db_row}{qw/id name url};
print " " $id " " $name " " $url;

Now I want to show the listings in pages since there are thousands of listings in the database. So it shall like this:

gtsee.com/cgi-bin/nph-dirsub.pl?invoice=invoices/merchant_invoice_999999?page=x
Among this x=1, 2, 3, 4, 5, 6, etc.

And I tried this to display in several pages but not working:

my $max_listings = 200;
#$tmp is the total listings in the database
my $total_pages = $tmp/$max_listings;
my $page = $query->param('page');
if($page = "") $page = 1;
my $start = ($page - 1) * $max_listings;
my $sql=SELECT id, name, url FROM free_dirs LIMIT $start, $max_listings;

Can anybody help me for this issue?

If you mean you want to only display X number of results per web screen, then use the 'LIMIT' command in your SQL query.

my $sql=SELECT id, name, url FROM free_dirs LIMIT 25;

Then you will have to programmatically add buttons to move forward or backwards through the list. Each button will trigger another SQL statement with a different LIMIT value.

Additionally, this condition will always be true:

if($page = "") $page = 1;

because you have used the assingment operator "=" instead of a comparison operator like "==" or "eq" to check the value of $page.

Currently I'm working like this:

gtsee.com/cgi-bin...

whoa, for a sec i thought you were pointing us to the goatse dude

:O

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.