#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    6
    Rep Power
    0
    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 &#0124; &#0124;
    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>";
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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).]

IMN logo majestic logo threadwatch logo seochat tools logo