how to make a "next page" and "last page" in a wincgi?

I want to list my table in browser,but the table is 1000 rows.I want to display it page by page,when I display one page, there are two button "next page" and "last page" at the bottom.What should I do?


Now I have a program to do it, but it can not work,the first page is right,the the next page is same as first page, what should I do?

project is yy.exe:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, HTTPApp, DBTables, Db;

type
  TWebModule1 = class(TWebModule)
    Database1: TDatabase;
    Query1: TQuery;
    Session1: TSession;
    PageProducer1: TPageProducer;
    procedure WebModule1Create(Sender: TObject);
    procedure WebModule1WebActionItem1Action(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
      const TagString: String; TagParams: TStrings;
      var ReplaceText: String);
    procedure WebModule1WebActionItem2Action(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WebModule1: TWebModule1;
  t_addr_c:string;
  t_name_c:string;

  aa:string;
implementation

{$R *.DFM}

procedure TWebModule1.WebModule1Create(Sender: TObject);
begin
  query1.close;
   query1.open;
   query1.FindFirst;
   t_name_c:=query1.fieldbyname('e_name_c').asstring;
   t_addr_c:=query1.FieldByName('e_addr_c').asstring;


end;

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
      query1.open;
      response.content:=pageproducer1.Content;
end;

procedure TWebModule1.PageProducer1HTMLTag(Sender: TObject; Tag: TTag;
  const TagString: String; TagParams: TStrings; var ReplaceText: String);
var i:integer;
begin
   if compareText(tagString,'tt')=0 then
   begin
     aa:='';
     for i:=1 to 5 do
      begin

       aa:=aa+'<tr>'+
          '<td width="240" bgcolor="#E8F3FF" height="18">'+
             trim(t_name_c)+
            '<p style="line-height: 100%; margin-top: 1; margin-bottom: 1">¡¡</td>'+
          '<td width="366" bgcolor="#E8F3FF" height="18">'+
             trim(t_addr_c)+
            '<p style="line-height: 100%; margin-top: 1; margin-bottom: 1">¡¡</td>'+
          '</tr>';
     query1.findNext;
     t_name_c:=query1.fieldbyname('e_name_c').asstring;
     t_addr_c:=query1.FieldByName('e_addr_c').asstring;

      end;
      replacetext:=aa;
   end;
end;

procedure TWebModule1.WebModule1WebActionItem2Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
      response.content:=pageproducer1.Content;
end;

end.




in pageproducer1.htmldoc:
<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<style type="text/css"><!-- A{TEXT-DECORATION:none}--></style>
<base target="_self">
<title></title>
<style fprolloverstyle>A:hover {color: #FF0000}
</style>
</head>

<body link="#000000">

      <table border="1" cellpadding="0" width="100%" height="282">
        <tr>
          <td bgcolor="#66CCFF" width="240" height="18">
            <p align="center" style="line-height: 100%; margin-top: 1; margin-bottom: 1"><font size="2">name</font></td>
          <td bgcolor="#66CCFF" width="366" height="18">
            <p align="center" style="line-height: 100%; margin-top: 1; margin-bottom: 1"><font size="2">address</font></td>
        </tr>

        <#tt>

      </table>
<p align="center" style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;</p>

<p align="center" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <a href="http://yangdong/scripts/yy.exe/last" target="_parent">last page</a>
<a href="http://yangdong/scripts/yy.exe/next" target="_parent">next page</a></font></span></p>


             
    </td>
  </tr>
</table>

</body>

</html>
LVL 1
adamyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
333Connect With a Mentor Commented:
hi,
you need to provide a page number as parameter to your program.
for example if you need to dislpay 100 rows in one page this could be done as:

http://yangdong/scripts/yy.exe?page=1

this means, that you need to display first page (first 100 rows). you have done this already. now for other pages you need to skip first page*100 records of your query (for example by using query1.moveby(100) ) and then output 100 rows.

you can read parameter page by using TWinCGIRequest.QueryFields.

also your links to next and last page should look like:
http://yangdong/scripts/yy.exe?page=1
you can provide more parameters to your program:
http://yangdong/scripts/yy.exe?page=4&ename=TEXT

A.
0
 
adamyAuthor Commented:
Adjusted points to 300
0
All Courses

From novice to tech pro — start learning today.