Hello [EMAIL PROTECTED],
This continuation post is from another post at [EMAIL PROTECTED]; it's posted here 
because this is more relevant to CGI.  Previously, I had 2 questions, one being 
pagination (the other question is yet addressed until pagination issue is understood). 
 Now, after following great advices from [EMAIL PROTECTED], I've looked up SQL's Limit 
and Offset concept, which I was able to understand-demonstrate by only getting first 
20 rows of the selections from mysql database.  However, when I tried to implement the 
rest of the rows, I got stuck as to how to approach what I wanted to do, which is to 
make a result that is similar to google search shown on the web.  Then, I searched 
more on the web about pagination without restricting my search to beginner and perl.  
Luckily, I found a lot more information and tried to use some of the concepts which 
were given.  Previously, Jeff 'japhy' Pinyan had give me some script (thanks, Jeff)  
that he used to do the similar thing that I'm trying to do, but
 I couldn't get all of his codes (ones near the end of his script).  Therefore, I had 
yet ventured the web again to better understand what I'm trying to do.  Yet, I have no 
luck in solving my issue with pagination.  In the end, I even used Jeff's code, only 
changing what is necessary (I think), to do see if it would work, and it didn't. I'm 
beginning to feel that I'm missing some fundamental concept of cgi, but I don't know 
what.  Can any one of you tell me what that may be by looking at my script?  Also, if 
possible, what is wrong with my code to get it to work?  Or, better yet, if it's 
really bad, could you show me how you would do it, as Jeff did, to see if I can get 
better sense of what I'm trying to do?  Or, if I'm being really dumb that I can't get 
this?  Currently, I'm going around a circle by testing my code each time I change to 
the script to see what it would do when it doesn't seem to change anything.  Thanks 
for your help or any input that may help me get the idea of what
 I can do to get the pagination.  Following is three of my numerous scripts that had 
been tested.
Angela 
----------------------------------------------------------------------------------------
#!/usr/bin/perl
use CGI':standard';
use diagnostics;
use DBI;
$q=new CGI;
$pp_disp=20;
$p=$q->param("p");
if ($p==1){$p=0;  $beg=$pp_disp*$p;}else{$beg=($pp_disp*$p)-($pp_disp);}
$break=($beg+$pp_disp)-1;
#connecting to mysql
my $dbh = DBI->connect("dbi:mysql:database", "usrname", "password") || die 
$DBI::errstr;
print "Content-type: text/html\n\n";
$offset=param('offset') || 0;
$limit=20;
my ($prev, $next) = ($offset-$limit, $offset + $limit);
$prev=0 if $prev <0;
$selecting=$dbh->prepare("select a, b, c, d FROM table limit $offset, $limit");
$nselcting=$dbh->prepare("select a, b, c, d FROM table limit $next, 1");
$arg=param('arg');
$selecting->execute();
print "<form name=form1 method=post action=>";
print "<TABLE><TABLE width=100% border=0>";
print "<tr><td width=6% bgcolor=#009900><Center><input type=checkbox name=checkbox 
value=checkbox></Center></td><TD width=7% bgcolor=#0099CC><FONT size=2 
face=Arial>A</FONT></TD><TD width=20% bgcolor=#0099CC><FONT size=2 
face=Arial>B</FONT></TD><TD width=40% bgcolor=#0099CC><FONT size=2 
face=Arial>C</FONT></TD><TD width=10% bgcolor=#0099CC><FONT size=2 
face=Arial>D</FONT></TD><TD width=5% bgcolor=#0099CC><FONT size=2 
face=Arial>E</FONT></TD></tr>";
while($dbselection=$selecting->fetchrow_arrayref()){
 if (($dbselection->[3])==2){($dbselection->[3])="me";}else{($dbselection->[3])="you";}
print "<tr><td width=6% bgcolor=#0099CC><Center><input type=checkbox name=checkbox 
value=checkbox></Center></td><TD width=7% bgcolor=#0099CC><FONT size=2 
face=Arial>$dbselection->[0]</FONT></TD><TD width=20% bgcolor=#0099CC><FONT size=2 
face=Arial>$dbselection->[1]</FONT></TD><TD width=40% bgcolor=#0099CC><FONT size=2 
face=Arial>$dbselection->[2]</FONT></TD><TD width=10% bgcolor=#0099CC><FONT size=2 
face=Arial>$dbselection->[3]</FONT></TD><TD width=5% bgcolor=#0099CC><FONT size=2 
face=Arial>E</FONT></TD></tr>";
}
print "</TABLE>";  
----------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
use CGI;#':standard';
use diagnostics;
use DBI;
#connecting to mysql
my $dbh = DBI->connect("dbi:mysql:database", "usrname", "password") || die 
$DBI::errstr;
$q=new CGI;
$pp_disp=20;
$p=$q->param("p");
$p=1;
if ($p==1){$p=0;  $beg=$pp_disp*$p;}else{$beg=($pp_disp*$p)-($pp_disp);}
$break=($beg+$pp_disp)-1;

$selecting=$dbh->prepare("select  a, b, c, d, e FROM table");$selecting->execute();
$dbselection=$selecting->fetchall_arrayref;
for ($i=$beg;$i<=$break;$i++){
  $result=$$dbselection[$i];
  foreach $each (@result) {print "$_"; }
}
-----------------------------------------------------------------------------------------------
#!/usr/bin/perl
use CGI':standard';
use diagnostics;
use DBI;
#connecting to mysql
my $dbh = DBI->connect("dbi:mysql:database", "usrname", "password") || die 
$DBI::errstr;
$offset=param('offset') || 0;
$limit=20;
my ($prev, $next) = ($offset-$limit, $offset+$limit);
$prev=0 if $prev <0;
  my $query = qq{ SELECT a, b, c, d FROM table where d=? LIMIT $offset, $limit };
  my $n_query = qq{ SELECT a, b, c, d FROM table where d=? LIMIT $next, 1 };
  my $arg = param('arg');
  my $sth = $dbh->prepare($query);
  $sth->execute($arg);
print "Content-type: text/html\n\n";
print "<form name=form1 method=post action=>";
print "<TABLE><TABLE width=100% border=0>";
  while (my $rec = $sth->fetchrow_arrayref) {
 print "<tr><td width=6% bgcolor=#0099CC>$rec->[0]</td><td width=6% 
bgcolor=#0099CC>$rec->[1]</td><td width=6% bgcolor=#0099CC>rec->[2]</td><td width=6% 
bgcolor=#0099CC>$rec->[3]</td><td width=6% bgcolor=#0099CC>rec->[3]</td></tr>";
    # do stuff with $rec
  }
print "</TABLE>";
  $sth = $dbh->prepare($n_query);
  $sth->execute($arg);
  
  # if this is not the FIRST set of records
  print qq{<a href="search.cgi?offset=$prev&arg=$arg"><<<</a>} if $prev != $offset;
  # if there are more rows to show after these
  print qq{<a href="search.cgi?offset=$next&arg=$arg">>>></a>} if $sth->rows;


---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Reply via email to