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

    fare una ricerca su più tabelle del DB

    Ciao, sto continuando ad usare lo script seguente che ho modificato per cercare in più tabelle dello stesso DB. Ma non va... ho cercato un po in giro per cercare di capire come fare ma sono rimasta abbastanza stralunata.

    NB in grassetto le mie modifiche

    codice:
    <%@LANGUAGE = JScript%>
    <html>
        <head>
            <title>Cerca nel sito</title>
        </head>
    <body>
    
    <h3>Cerca nel sito</h3>
    
    <form method="POST" action="cerca.asp?cerca=OK">
        <input type="text" name="stringa">
        <input type="submit" value="Cerca">
    </form>
    
    <%
        var cerca = new String(Request.QueryString("cerca"));
        var testo = new String(Request.Form("stringa"));
        var apice = testo.replace(/'/g,"''");
        var stringa = apice.split(" ");
        if (cerca == "OK")
        {
            if (testo == "" || testo == "undefined")
            {
                Response.Write("
    
    Inserire almeno una parola per effettuare una rcerca</p>");
            }
            else
            {
                var Cn = new ActiveXObject("ADODB.Connection");
                    Cn.Open("driver={Microsoft Access Driver (*.mdb)};dbq=" + Server.MapPath("/mdb-database/contenuto.mdb"));
                var sql = "SELECT * FROM Notizie AND Documenti AND Progetti WHERE";
                for (var i=0; i<stringa.length; i++)
                {
                    if (i > 0)
                    {
                        sql += " AND";
                    }
                    sql += " Titolo LIKE '%" + stringa[i] + "%'";
                }
                var Mostra = Cn.Execute(sql);
    
                if (Mostra.EOF)
                {
                    Response.Write("
    
    Nessun risultato</p>");
                }
                else
                {
                    while (!Mostra.EOF)
                    {
                        with (Response)
                        {
                            Write("
    
    ");
                            Write("" +Mostra("Titolo") + "
    ");
                            Write(Mostra("Corpo"));
                            Write("</p>");
                            Mostra.MoveNext();
                        }
                    }
                }
                Cn.Close();
            }
        }
    %>
    
    </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di Vash SD
    Registrato dal
    Sep 2006
    Messaggi
    502
    prova a modificare questa parte:
    codice:
    var sql = "SELECT * FROM Notizie AND Documenti AND Progetti WHERE";
    così:
    codice:
    var sql = "SELECT * FROM Notizie WHERE Documenti AND Progetti";

  3. #3
    codice:
    var sql = "SELECT * FROM Notizie, Documenti, Progetti WHERE";

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 © 2026 vBulletin Solutions, Inc. All rights reserved.