Visualizzazione dei risultati da 1 a 9 su 9

Discussione: Motorino di ricerca

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493

    Motorino di ricerca

    Salve,
    ho questo motorino di ricerca che opera su un Ms database di una bibliotechina.
    vorrei poter mettere tre radiobutton per far scegliere se ricercare nel campo titolo, autore o editore.
    Questi radiobutton dovrebbero avere una stringa che mi fa cambiare la parola nella riga di codice qui sotto

    codice:
                    sql += " Titolo LIKE '%" + stringa[i] + "%'";
    Se metto titolo mi dovrebbe scrivere totolo like
    se metto autore, autore like
    se metto editore, edit like
    quindo avrei bisogno di una variabile che mi faccia cambiare la parola.
    come si fa? potreste dirmi il codice da mettere? grazie
    qui c'è tutta la pagina (unica pagina per la ricerca)
    grazie di nuovo
    codice:
    <%@LANGUAGE = JScript%>
    <html>
        <head>
            <title>Cerca nel catalogo della Biblioteca</title>
            <style type="text/css">
    <!--
    .Stile1 {font-family: "ms Reference Sans Serif", Arial, tahoma}
    .Stile2 {
    	font-size: 12px;
    	color: #0000FF;
    }
    body {
    	background-color: #6C7AA1;
    }
    -->
            </style>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
    <body class="Stile1">
    
    <h3 align="center">Cerca nel catalogo della nostra Biblioteca</h3>
    <h3></h3>
    <form action="ricerca.asp?cerca=OK" method="POST" class="Stile2">
      <div align="center">[img]../Immagini/Libro-specchio.jpg[/img]    
    
        <input type="text" name="stringa">
          <input type="submit" value="Cerca"> 
      </div>
    </form>
    <span class="Stile2">
    <%
        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("/database/biblio.mdb"));
                var sql = "SELECT * FROM catalogo 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(("Editore: ") + Mostra("Editore"));
                            Write("
    ");
    						Write(("Autore: ") + Mostra("Autore")  + (" ") +Mostra ("Anno"));
                            Write("</p>");
    						Write ("<hr>")
                            Mostra.MoveNext();
                        }
                    }
                }
                Cn.Close();
            }
        }
    %>
    </span>
    </body>
    </html>

  2. #2
    codice:
    <input type="radio" name="campo" value="titolo" checked>Titolo
    
    <input type="radio" name="campo" value="autore">Autore
    
    <input type="radio" name="campo" value="editore">Editore
    codice:
    var campo = new String(Request.Form("campo"));
    
    SQL += campo + " LIKE '%" + stringa[i] + "%'";

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493
    Prima di tutto grazie per l'aiuto!

    mi dà questo errore
    codice:
    Microsoft JScript runtime error '800a138f' 
    
    Object expected 
    
    /biblio/ricerca.asp, line 62
    dove sbaglio?
    Questa è la pagina
    codice:
    <%@LANGUAGE = JScript%>
    <html>
        <head>
            <title>Cerca nel catalogo della Biblioteca</title>
            <style type="text/css">
    <!--
    .Stile1 {font-family: "ms Reference Sans Serif", Arial, tahoma}
    .Stile2 {
    	font-size: 12px;
    	color: #0000FF;
    }
    body {
    	background-color: #6C7AA1;
    }
    .Stile4 {font-size: 12px}
    -->
            </style>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
    <body class="Stile1">
    
    <h3 align="center">Cerca nel catalogo della nostra Biblioteca</h3>
    <h3></h3>
    <form action="ricerca.asp?cerca=OK" method="POST" class="Stile2">
      <div align="center">
        
    
    [img]../Immagini/Libro-specchio.jpg[/img]    
    
          <input type="text" name="stringa">
    </p>
        
    
        
    
    
          <input type="radio" name="campo" value="titolo" checked>
          Titolo
    
          <input type="radio" name="campo" value="autore">
          Autore
    
          <input type="radio" name="campo" value="editore">
        Editore</p>
        
    
    
    
          <input name="submit" type="submit" value="Cerca">
          <%
        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 ricerca</p>");
            }
            else
            {
                var Cn = new ActiveXObject("ADODB.Connection");
                    Cn.Open("driver={Microsoft Access Driver (*.mdb)};dbq=" + Server.MapPath("/mdb-database/biblio.mdb"));
                var sql = "SELECT * FROM catalogo WHERE";
                for (var i=0; i<stringa.length; i++)
                {
                    if (i > 0)
                    {
                        sql += " AND";
                    }
    					var campo = new String(Request.Form("campo"));
    
    					SQL += campo + " 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(("Editore: ") + Mostra("Editore"));
                            Write("
    ");
    						Write(("Autore: ") + Mostra("Autore")  + (" ") +Mostra ("Anno"));
                            Write("</p>");
    						Write ("<hr>")
                            Mostra.MoveNext();
                        }
                    }
                }
                Cn.Close();
            }
        }
    %>
    </p>
          </p>
      </div>
    </form>
    <span class="Stile2"></span>
    </body>
    </html>
    grazie ancora

  4. #4
    Non vedo dove hai inserito questo:
    codice:
    var campo = new String(Request.Form("campo"));

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493
    è subito sopra a sql +=campo + like...
    l'ho messo ma mi dà quell'errore
    codice:
    {
                    if (i > 0)
                    {
                        sql += " AND";
                    }
    					var campo = new String(Request.Form("campo"));
    
    					SQL += campo + " LIKE '%" + stringa[i] + "%'";
                }
                var Mostra = Cn.Execute(sql);
                if (Mostra.EOF)

  6. #6
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493
    nessuno sa aiutarmi???

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493
    dai, non ci credo che nessuno sappia aiutarmi, perchè nessuno mi risponde???

  8. #8
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    493
    potete aiutarmi?

  9. #9
    Forse qui puoi trovare degli esempi adatti al tuo problema

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.