tout est presque dit dans le titre, bien évidemment pour tester ce cgi, il faudrait au préalable le serveur et la base de données mysql 'autos' de mon exemple et la bibliothèque cgilib qui appartient à un de mes professeurs M. François piette
http://www.overbyte.be
Source / Exemple :
program Cgi_Autos;
{$APPTYPE CONSOLE}
uses
sysutils,CgiLib,ActiveX,Db,ADODB,classes;
var
ADOConnection :TAdoConnection;
ADOQuery :TAdoQuery;
ADOQuery1 :TADOQuery;
DocumentData :TMemoryStream;
DocumentError :TMemoryStream;
idauto :string;
km :string;
marque :string;
annee :string;
cylindree :string;
prix :string;
contact :String;
LaTable :string;
count :string;
total :string;
pagination :string;
js :string;
indds :string;
Querystring :string;
query :string;
nbelem :integer;
valeur :integer;
reste :integer;
j :integer;
indd :integer;
tot :integer;
totaux :integer;
begin
GetEnv('QUERY_STRING', Querystring);
GetValue(Pchar(Querystring), 'page',query);
if indd <> 0 then
begin
indds := query;
end
else
begin
indd := 0;
indds := inttostr(indd);
end;
CoInitialize(nil);
ADOConnection :=TAdoConnection.Create(nil);
ADOQuery :=TAdoQuery.Create(nil);
DocumentData := TMemoryStream.Create;
try
ADOConnection.LoginPrompt :=FALSE;
ADOConnection.ConnectionString :='Provider=MSDASQL.1;'+
'Data Source=sample-MySQL;'+
'DATABASE=test;'+
'SERVER=localhost;'+
'UID=nas;'+
'PASSWORD=3591;'+
'PORT=3306;'+
'OPTION=1;'+
'STMT=;"';
ADOConnection.Open;
ADOQuery.Connection :=ADOConnection;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select *from autos order by title limit '+indds+',10');
ADOQuery.Open;
LaTable := '';
count := '';
pagination :='';
while not ADOQuery.Eof do begin
idauto := ADOQuery.FieldByName('id_auto').AsString;
marque := ADOQuery.FieldByName('title').AsString;
cylindree := ADOQuery.FieldByName('type').AsString;
km := ADOQuery.FieldByName('km').AsString + ' '+ 'Km';
annee := ADOQuery.FieldByName('annee').AsString;
prix := ADOQuery.FieldByName('price').AsString +' '+'Eur';
contact := ADOQuery.FieldByName('contact').AsString;
LaTable := LaTable + '<TR bgcolor="#FFFFFF" class="table_auto">' +
'<TD width="18%" id="marque">' +
'<a href="javascript:popup(''http://localhost/html-cours/images/'+idauto+'.jpg'')" onMouseOver="linkOn(this, ''marque'')" onMouseOut="linkOff(this, ''marque'')" title="voir photo">'+marque+'</a>'+
'</TD >' +
'<TD width="15%">' +
cylindree+
'</TD>' +
'<TD width="12%">' +
km +
'</TD>' +
'<TD width="6%">' +
annee +
'</TD>' +
'<TD width="8%">'+
prix +
'</TD>'+
'<TD width="21%" id="detail"><center>'+
'<a href="javascript:repopup(''http://localhost/scripts/cgi_autos_details.exe?idauto='+idauto+''')" onMouseOver="linkOn(this, ''detail'' )" onMouseOut="linkOff(this, ''detail'')" title="fiche technique">détails</a>'+
'</center></TD>'+
'</TR>';
ADOQuery.Next;
end;
begin
ADOQuery1 :=TAdoQuery.Create(nil);
ADOConnection.Open;
ADOQuery1.Connection :=ADOConnection;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select *from autos order by title');
ADOQuery1.Open;
totaux:=ADOQuery1.recordcount;
total := inttostr(totaux);
count := count + '<table><tr><td>'+total+' voitures mises en annonce</td></tr></table>';
end;
// L A P A G I N A T I O N :
begin
tot:=totaux;
nbelem := 10;
valeur := tot div nbelem;
reste := tot mod nbelem;
if tot >= 10 then
begin
if reste <> 0 then
valeur:=valeur+1
else
valeur:=valeur;
end
else
begin
valeur:=1;
end;
for j:=1 to valeur do
begin
js := inttostr(j);
indd := j * 10 - 10;
indds := inttostr(indd);
pagination := pagination + '<a class="lien" href="http://localhost/Scripts/'+
'Cgi_Autos.exe?page='+indds+'" onmouseover="this.className=''tabover''" onmouseout="this.className=''tabnormal''"><font color="#FFFFFF" size="2"> '+js+' </font></a>';
end;
end;
ScanTaggedHtml('mysqllist.html',
['LA_TABLE', LaTable,
'count', count,
'pag', pagination],
DocumentData);
ADOQuery.Close;
CgiOutput('text/html', '', DocumentData);
except
on E:Exception do begin
DocumentError := TMemoryStream.Create; // Il faut créer le stream !
ScanTaggedHtml('SimpleErrorPage.html',
['CLASSNAME', E.ClassName,
'MESSAGE', E.Message],
DocumentError);
CgiOutput('text/html', '', DocumentError);
DocumentError.Destroy;
end;
end;
ADOQuery.Destroy;
ADOQuery1.Destroy;
Adoconnection.Destroy;
DocumentData.Destroy;
CoUninitialize;
end.
Conclusion :
à vous de juger le code!!!
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.