Newbie questions: how to show a listing in pages

Reply

Join Date: Nov 2007
Posts: 11
Reputation: hhheng is an unknown quantity at this point 
Solved Threads: 0
hhheng hhheng is offline Offline
Newbie Poster

Newbie questions: how to show a listing in pages

 
0
  #1
Mar 10th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Newbie questions: how to show a listing in pages

 
0
  #2
Mar 10th, 2008
If you mean you want to only display X number of results per web screen, then use the 'LIMIT' command in your SQL query.
  1. 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!"
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Newbie questions: how to show a listing in pages

 
0
  #3
Mar 10th, 2008
Additionally, this condition will always be true:

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,604
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Newbie questions: how to show a listing in pages

 
0
  #4
Mar 17th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC