| | |
Newbie questions: how to show a listing in pages
![]() |
•
•
Join Date: Nov 2007
Posts: 11
Reputation:
Solved Threads: 0
I'm showing a directory listing in one page now, but I want to show it in pages.
Currently I'm working like this:
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:
And I tried this to display in several pages but not working:
Can anybody help me for this issue?
Currently I'm working like this:
•
•
•
•
gtsee.com/cgi-bin/nph-dirsub.pl?invoice=invoices/merchant_invoice_999999
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.
•
•
•
•
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;
•
•
Join Date: Sep 2007
Posts: 176
Reputation:
Solved Threads: 20
If you mean you want to only display X number of results per web screen, then use the 'LIMIT' command in your SQL query.
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.
Perl Syntax (Toggle Plain Text)
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.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
Additionally, this condition will always be true:
because you have used the assingment operator "=" instead of a comparison operator like "==" or "eq" to check the value of $page.
Perl Syntax (Toggle Plain Text)
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.
![]() |
Other Threads in the Perl Forum
- Previous Thread: Regular Expression
- Next Thread: Urgent help needed to improve perl script
| Thread Tools | Search this Thread |






