Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 1st, 2000, 08:00 PM
razormind razormind is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 6 razormind User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to razormind
I tried a few examples to limit the output
of this table to 10 records at a time but I
can't seem to figure it out yet. Can someone please... shed some light.

$sth = $dbh->prepare($getrec_city);
$sth->execute | |
die "Could not open Record.......";
print "<table border cellpadding=3 cellspacing=0 width=99%><p>n";
print "<tr bgcolor=cc6699><th>#Rec</th><th>City</th>n";
print "<th>Company Name</th><th>Phone</th><th>Category</th><tr>n";
while (@row=$sth->fetchrow_array) {
print "<tr align=left><td $flc><center>$row[13]</center></td>n";

if ($row[4] eq "") {
$row[4] = "N/A ";
}
if ($row[7] eq "") {
$row[7] = "N/A";
}
print "<td $flc>$row[4] $row[5]</td>n";
print "<td $flc>";
print "<A HREF=$dblnk?action=GO&con_id=$row[13]>$row[2]</A></td>n";
print "<td $flc> $row[7]</td>n";
print "<td $flc> $row[1]</td></tr>n";
}
print "</table></p>";

}
if ($city eq "ALL_Cities") {
$sth = $dbh->prepare($getrec_city2);
$sth->execute | |
die "Could not open Record.......";
print "<table border cellpadding=3 cellspacing=0 width=99%><p>n";
print "<tr bgcolor=cc6699><th>#Rec</th><th>City</th>n";
print "<th>Company Name</th><th>Phone</th><th>Category</th><tr>n";
while (@row=$sth->fetchrow_array) {
print "<tr align=left><td $flc><center>$row[13]</center></td>n";

if ($row[4] eq "") {
$row[4] = "N/A ";
}
if ($row[7] eq "") {
$row[7] = "N/A";
}
print "<td $flc>$row[4] $row[5]</td>n";
print "<td $flc>";
print "<A HREF=$dblnk?action=GO&con_id=$row[13]>$row[2]</A></td>n";
print "<td $flc> $row[7]</td>n";
print "<td $flc> $row[1]</td></tr>n";
}
print "</table></p>";

Reply With Quote
  #2  
Old July 3rd, 2000, 04:59 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
razormind,
i will show you an example how we can display limited results with "next|previuos" links.

you can use same logic for your script.


####navigate.cgi#######


#!/usr/bin/perl

use DBI;
use CGI;

$q=new CGI;

print $q->header;

$dbh=DBI->connect('dbi:mysql:database','usr','pwd');

$sql="select * from login";
# first get the total number of records from the database.

$sth = $dbh->prepare($sql);

$numrows = $sth->execute;

$offset=$q->param('offset');


$limit=5;

#total records 5

#next determine if offset has been passed to script, if not use 0
if (length($offset)==0) {
$offset=1;
}


$query="select * from login order by usr limit $offset,$limit";

$sth= $dbh->prepare($query);
$rv= $sth->execute;


print "<table>n";
print "<tr><td>Username</td><td>Password</td></tr>n";


while(@row = $sth->fetchrow_array) {

#print your result here

print "<tr><td>n";
print $row[0]."</td><td>n";
print $row[1];
print "</td></tr>n";
}
print "</table>n";

# calculate number of pages needing links

$pages=int($numrows/$limit);

if ($numrows%$limit) {
#has remainder so add one page
$pages++;
}

for ($i=1;$i<=$pages;$i++) {
#loop thru
$newoffset=$limit*($i-1);
print "<a href="navigate.cgi?offset=$newoffset">$i</a> * n";
}

#check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
# not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href="navigate.cgi?offset=$newoffset">NEXT</a><p>n";
}

if ($offset>0) {
# bypass PREV link if offset is 0
$prevoffset=$offset-5;
print "<a href="navigate.cgi?offset=$prevoffset">PREV</a>n";
}

################-
see the above script working online at:
http://www.samakcreations.com/cgi-bin/navigate.cgi

####################
This logic is borrowed from a php article.

##########

------------------
SR -
webshiju.com

"The fear of the LORD is the beginning of knowledge..."


[This message has been edited by Shiju Rajan (edited July 07, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Next & Prev Buttons For Output


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway