Mirabilweb
a- a+

Creare un sistema per la gestione delle news (Parte II)

Pagina 2 di 8

Abbiamo creato il database, ora creiamo una pagina pervisualizzare il sommario delle news. La pagina sichiamerà index.asp e conterrà ilseguente codice:

 

<html><head><title>Creazione Sistema per la gestione delle news</title></head> <body> <p align="center"><font size="2" face="Verdana"><b>Creazione Sistema per la gestione delle news</b></font></p><p align="left"><font size="2" face="Verdana"><b>Sommario:</b></font></p><p align="left"><font size="2" face="Verdana"><!-- #INCLUDE FILE="db.asp" --><!-- #include file="adovbs.inc" --><%‘ APRE LA CONNESSIONE AL DB (=DATABASE)Set RecSet = Server.CreateObject("ADODB.Recordset")News = "SELECT * FROM news ORDER BY Id DESC"RecSet.Open News, Connect, adOpenStatic, adLockOptimistic%> <%‘ SE NON TROVA NESSUN RECORD (=NESSUNA NEWS) TI VISUALIZZA IL SEGUENTE MESSAGGIOif RecSet.eof thenResponse.Write "<br><center><b>Nessuna News Trovata.</b></center>"‘ … ALTRIMENTI…else%>   <%‘… INIZIA A RIPETE I RECORD E A VISUALIZZARLI NELLA PAGINA ASPDo Until RecSet.EOF %>

 

<%=RecSet("Data")%>  - <b><a href="visualizza.asp?id=<%=RecSet("id")%>"> <%=RecSet("Titolo")%></a></b><br> <%‘METTE FINE ALLA CONNESSIONE AL DB E METTE FINE ALLA PRECEDENTE CONDIZIONE     RecSet.MoveNextLoopRecSet.CloseConnect.CloseEnd IF%> </font><p align="right"><a href="http://www.mirabilweb.tk"><font size="2" face="Verdana"><b>byMirabil Web Computer - Tutto sui PC!</b></font></a></p></body></html>

 

Da notare è la creazione di due pagine:

  • Db.asp, che conterrà il seguente codice, per la connessione al database:

 

<%     Set Connect = Server.CreateObject("ADODB.Connection")‘DA MODIFICARE CON UN PERCORSO VIRTUALE. ES. IL DB SI TROVA IN‘http://COMPUTER.IT/MDB-DATABASE/NEWS.MDB SI INSERIRA’ /MDB-DATABASE/NEWS.MDBConnect.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("/mdb-database/news.mdb")%>

 

 

Continua>>>