Linda,
    Below is an example script I am developing that does something similar
to what you describe. It is a flawed 'solution' in that it grabs all the
records, even if you set it (and this is hard coded - my bad) to view 5 at a
time. A better approach is to use a procedure that is part of a server side
package, but this was developed to play with cgi. It uses the standard
package and addresses the issue of printing table data in a loop by using
*table and *Tr to allow table and table row methods to be split into
start_table and end_table as well as start_Tr end_Tr. If any one knows of an
elegant way to do the same I would like to see it.

# Form example
#
use strict;
#  *standardelement allows you to split into start_element end_element pairs
use CGI qw( :standard *table *Tr);
use DBI;
use DBD::Oracle;
############################################################################
#######################
# first get the data

my $host   = "localhost";                       # host
my $sid    = "oracle";                            # Schema IDentifier
my $dbuser = "scott";                           # DataBase Username
my $dbpw   = "tiger";                           # DataBase PassWord
my $dbcs   = "dbi:Oracle:host=$host;sid=$sid";  # DataBase Connect String
my $dbh;
eval {
$dbh = DBI->connect($dbcs, $dbuser, $dbpw, {
       RaiseError => 1,                         # required for eval to pop
$@
    PrintError => 0,
       AutoCommit => 0
    }); #using eval or dberr("C");
};
if ($@) {                                       # if an error occurs in eval
func this will be 'true'
 print"Connect eval had a problem! I quit!\n";
 exit;
}
my $sql = "select ename, job, hiredate from emp";
my $sth;
unless ($sth = $dbh->prepare($sql)) {
 $dbh->disconnect;
 print"Prepare fails: $DBI::errstr\n";
};
$sth->execute;
my $ar = $sth->fetchall_arrayref;
$sth->finish;
$dbh->disconnect;
my @trr;
my %bgca = ( -bgcolor => "#aaaaaa",
    -align   => "center",
     );

my @thdr = qw( Row Name Job Hired );

my $i = 1;                                   # row number
my $rset = 7;                                # rows in return set
my $rss = param('nrec') ? param('nrec') : 1; # record set start number - Not
array index
my $lrs = $rss + $rset;                      # last record in set
my $tris = @$ar;                             # total records in set

print header(   -type    => "text/html"),
 start_html( -title   => "Forms, Tables and PopLists",
    -bgcolor => "#ffffcc",
     ),
 hr,
 p( h2( { -align => "center" }, "Server Name:", em( server_name ) ) ),
 hr,
 start_table(
  { -border =>  1,
    -width  => "100%",
  } ),
  th( \%bgca, \@thdr );
  foreach (@$ar) {
   unshift @$_, $i;
   print start_Tr(),
   td( \%bgca,
     $_ ),
   end_Tr if ( ($i < $lrs) and ($i >= $rss) );
   if ( $i == $lrs ) {
    last;
   } else {
    $i++;
   }
  }
 print end_table;
 if ( $lrs <= $tris ) {
  print a( { -href => "db_fex.pl?nrec=$i" }, " Click here to see the next
set of records" );
 } else {
  print" No more records", br;
 }
 print end_html;

HTH, David

"Linda Xu" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi,
>
> I am a beginner of using perl.
>
> I need to write a script to retrived records from oracle database and
> display them in CGI web page by n records per page.
>
> I use an array reference to store all the records :
>
>      $re_list_ref=$dbh->selectall_arrayref($sql,{}, @bind);
>
> How could I make a URL to display next n records? Do I need to create a
> package to print the records? or use a template file? or redirect to
itself?
>
>
>
>
> TKS
>
> Linda Xu
> General Magic
>
>


Reply via email to