Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [SCRIPT]News dinamiche con db access, asp e xml

    Ieri alla fine sono riuscito ad ottenere ciò che volevo, con un po' di fatica ma il risultato è ottimo. Siccome sono amante dell'open source vi posto il tutto.

    Il kit che segue ha la funzione di:

    1)pescare dei dati da un db
    2)dichiararli come variabili tramite una pagina asp
    3)creare una pagina xml sempre tramite la pagina asp
    4)riprodurre le news in flash, formattando il testo con un semplice foglio di stile css

    Istruzioni:
    1) creare un foglio di stile foglio_stile.css con questo codice:

    a:link {
    color: #FF9900;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    display: inline;
    text-decoration:underline;
    }
    a:hover {
    color: #000000;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: bold;
    display: inline;
    text-decoration:underline;
    }


    body {
    color: #336699;
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size: 10px;
    font-weight: normal;
    display: inline;
    }


    2)creare un file asp di nome scroll_news.asp con questo codice:


    <%
    Response.Expires = 0
    Dim rs, cn, sql, fs
    Dim titolo, testo, image
    Dim filepath, logfile

    Set rs = Server.CreateObject("ADODB.Recordset")
    Set cn = Server.CreateObject("ADODB.Connection")
    sql = "SELECT * FROM tbNews ORDER BY tbNews.IDNews"
    strAccessDB = "db.mdb"
    strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(strAccessDB)
    cn.Open strConn

    Set rs.ActiveConnection = cn
    rs.CursorType = adOpenStatic
    rs.LockType = adLockOptimistic
    rs.Source = "tbNews"
    rs.Open sql, cn

    'crea un FileSystem oggetto
    Set fs = CreateObject("Scripting.FileSystemObject")

    'trova il path del file
    filePath = Server.mapPath ("ospite.xml")

    'costruisci la stringa da scrivere
    'news = titolo & testo & link

    news = "<?xml version=""1.0"" encoding=""UTF-8""?>" & VbCrlF &_
    "<rss version=""0.91"">" & VbCrlF &_
    "<channel>" & VbCrlF &_
    "<title>TITOLO</title>" & VbCrlF &_
    "<description>TESTO</description>" & VbCrlF &_
    "<link>LINK</link>"

    do while not rs.eof

    'raccogli le informazioni che vuoi scrivere
    titolo = rs("Titolo")
    testo = rs("Testo")
    image = rs("Image")
    link = rs("Link")

    news = news &_
    "<item>" & VbCrlF &_
    "<title><![CDATA["&titolo&"]]></title>" & VbCrlF &_
    "<description src="""&image&""" width=""65"" height=""65"">"&testo&"</description>" & VbCrlF &_
    "<link><![CDATA["&link&"]]></link>" & VbCrlF &_
    "</item>" & VbCrlF
    rs.movenext
    loop

    news = news &_
    "</channel>" & VbCrlF &_
    "</rss>"

    'aprila per scrivere
    Set LogFile = fs.OpenTextFile(filepath, 8)

    'scrivi
    logfile.WriteLine news

    'chiudi
    set logfile=nothing
    set fs=nothing

    set logfile = nothing
    set fs = nothing

    rs.Close
    Set rs=Nothing
    %>

    3)creare un file xml vuoto di nome ospite.xml

    4)creare un database access di nome db.mdb avente:
    - una tabella di nome tbNews
    - composta dai campi:
    - IDNews
    - Titolo
    - Testo
    - Image
    - Link
    e popolarlocon testi e percorsi link e immagini

    5)posizionare le immagini (di abbellimento news) nella dir principale con tutti gli altri file

    6)creare un movie flash nel seguente modo:
    - creare tre layer ognuno composta da 1 frame
    - nel primo trascinare un'istanza del componente textarea
    - nominare gli altri due rispettivamente "xml" e "functions"
    - nel primo frame di xml inserire questa azione:
    ApriXML();
    function ApriXML() {
    textArea_mc.text = "Caricamento dell'XML...";
    mioxml = new XML();
    myarray = new Array();
    myarray2 = new Array();
    myarray3 = new Array();
    myarray4 = new Array();
    titleitem = new Array();
    description = new Array();
    image = new Array();
    link = new Array();
    filexml = "ospite.xml";
    mioxml.load(filexml);
    mioxml.ignoreWhite = true;
    mioxml.onLoad = ElaboraXMLvideo;
    function ElaboraXMLvideo(success) {
    if (mioxml.loaded) {
    myarray = mioxml.childNodes;
    for (j=0; j<=myarray.length; j++) {
    if (myarray[j].nodeName == "rss") {
    myarray2 = myarray[j].childNodes;
    for (i=0; i<=myarray2.length; i++) {
    if (myarray2[i].nodeName == "channel") {
    myarray3 = myarray2[i].childNodes;
    for (k=0; k<=myarray3.length; k++) {
    if (myarray3[k].nodeName == "title") {
    loading = myarray3[k].childNodes.toString();
    }
    if (myarray3[k].nodeName == "description") {
    loading = loading+" - "+myarray3[k].childNodes.toString();
    }
    if (myarray3[k].nodeName == "item") {
    myarray4 = myarray3[k].childNodes;
    for (n=0; n<=myarray4.length; n++) {
    if (myarray4[n].nodeName == "title") {
    titleitem.push(myarray4[n].childNodes.toString());
    } else if (myarray4[n].nodeName == "description") {
    description.push(myarray4[n].childNodes.toString());
    image.push("[img]"+myarray4[n].attributes.src+"[/img]");
    } else if (myarray4[n].nodeName == "link") {
    link.push(myarray4[n].childNodes.toString());
    }
    }
    }
    }
    }
    }
    }
    }
    textArea_mc.text=""
    populateTextArea();
    } else {
    textArea_mc.text="Errore nell'apertura del file XML."
    }
    // Libero risorse
    delete myarray;
    delete myarray2;
    delete myarray3;
    delete myarray4;
    delete mioxml;

    }
    }

    - nel primo frame di functions inserire questa azione:
    function populateTextArea() {
    //inizializzo il componente TextArea
    textArea_mc.html = true;
    textArea_mc.wordWrap = true;
    textArea_mc.multiline = true;
    /******************************/
    //Carico il CSS
    stileCSS = new TextField.StyleSheet();
    stileCSS.load("foglio_stile.css");
    stileCSS.onLoad = function(success) {
    if (success) {
    textArea_mc.styleSheet = stileCSS;
    maxn = link.length-1;
    for (i=0; i<=maxn; i++) {
    // Inserisco i dati nella textArea aggiungendo i Tag HTML per la formattazione
    textArea_mc.text += ""+titleitem[i]+"";
    textArea_mc.text += "
    <body>"+image[i]+description[i]+"</body>

    ";
    }
    } else {
    textArea_mc.text = "Errore nel caricamento del CSS";
    }
    };
    //trace(textArea_mc.text)
    }
    stop();


    6) eseguire la pagina asp in modo da riempire il file xml con i dati immessi nel database

    7)salvare il tutto e pubblicare il fla

    8)that's all falk =)

    buon divertimento
    byeee

    p.s.: la guida penso sia molto esaustiva, quindi se avete problemi per favore pensateci e ragionateci sopra qualche secondo prima di chiedere info a riguardo.

    :metallica

  2. #2
    Utente bannato
    Registrato dal
    Feb 2003
    Messaggi
    392
    potresti postare lo script da scaricare possibilmente ed una demo??
    kiedo troppo???

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    121
    mi associo anche io alla richiesta di una demo, se possibile
    grazie
    mila

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.