Ankündigung

Einklappen
Keine Ankündigung bisher.

autocomplete mehrere Text Felder mit einer Such Datei

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • autocomplete mehrere Text Felder mit einer Such Datei

    Hallo zusammnen,

    ich hänge gerade an einen Probelm.

    Ich habe eien Artikel DB auf die ich zugreife un in der Ich Arikel Text mit autocomplete suche.

    Ich möchte ihn jedem Formularfeld einen Artikel aus dieser DB suchen

    Klar ich könnte 13x search.php dateien machne für die 13 Artikel Text Felder.
    Gibt es da eine schönerer Lösung wie ich das Feld an eine search.php übergeben kann?

    Es müsste in die formular id bei search rein ich setzte eine variable feld
    Leider klappt das nicht..
    trägt man für "feld" die Formular I "milchkaffee" geht es.

    Hat jemand eine Idee für mich?


    <script>
    ac.attach({
    target: document.getElementById(feld) ,
    data: "search.php",
    });
    </script>



    PHP-Code:

    <html>
    <head>
      <script src="../js/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
      <link rel="stylesheet" href="../../css/werbeaktion.css" type="text/css" />
      <script src="../../js/autocomplete.js"></script>
      <link rel="stylesheet" href="../../css/autocomplete.css">

      <style>

      body { /* Hintergrund Layout */
      background-image: url('../../vorlage/hintergrundHoch.jpg');
      background-repeat: no-repeat;
      background-attachment: fixed;
      background-size: 100% 100%;
    }

        #myForm{
          font-family: 'HL_LT';
          font-size: 18px;
          padding: 5px 20px;
          max-width:800px;
          background:#f2f2f2
        }
        label,input,.acWrap,select {
          font-family: 'HL_LT';
          font-size: 18px; padding: 3px 0px;

        }
        input{
          padding:5px
        }
        label{
          padding:5px 0
        }  
        select{
          padding:5px
        }
        span{
          font-family: 'HL_LT';
          font-size: 18px;
          padding:20px 0px
        }
    </style>


    <title>Kaffee Preis Gross</title>
    </head>
    <body>



    <?php


    require_once "../../funktion/pdo_verbindung.php";

              
    $sql "SELECT * FROM kaffeepreise";
              
    $result $pdo->query($sql);
              
    $row_count $result->rowCount();
              if (
    $result->rowCount() > 0) {
                while (
    $row $result->fetch()) {

                  
    $kaffee_klein $row["kaffee_klein"];
                  
    $kaffee_normal $row["kaffee_normal"];
                  
    $kaffee_gross $row["kaffee_gross"];
                  
    $cappuccino_klein$row["cappuccino_klein"];
                  
    $cappuccino_normal$row["cappuccino_mormal"];
                  
    $cappuccino_gross$row["cappuccino_gross"];
                  
    $espresso $row["espresso"];
                  
    $espresso_doppelt$row["espresso_doppelt"];
                  
    $milchkaffee$row["milchkaffee"];
                  
    $latte_macchiato$row["latte_macchiato"];
                  
    $heisse_schokolade$row["heisse_schokolade"];
                  
    $tee$row["tee"];


                  
    $kaffee_kleinp_preis $row["kaffee_klein_preis"];
                  
    $kaffee_normal_preis $row["kaffee_normal_preis"];
                  
    $kaffee_gross_preis $row["kaffee_gross_preis"];
                  
    $cappuccino_klein_preis $row["cappuccino_klein_preis"];
                  
    $cappuccino_normal_preis $row["cappuccino_mormal_preis"];
                  
    $cappuccino_gross_preis $row["cappuccino_gross_preis"];
                  
    $espresso_preis $row["espresso_preis"];
                  
    $espresso_doppelt_preis $row["espresso_doppelt"];
                  
    $milchkaffee_preis $row["milchkaffee_preis"];
                  
    $latte_macchiato_preis $row["latte_macchiato_preis"];
                  
    $heisse_schokolade_preis $row["heisse_schokolade_preis"];
                  
    $tee_preis$row["tee_preis"];




            }
          }


    ?>



    <form name="frmUser" id="myForm" method="post" action="">

            <table border ="0">
      <tr><td>
          <label for="kaffee_klein">Kaffee Klein</label>
      </td><td>
          <input type="text" id="kaffee_klein" name="kaffee_klein" value="<?php echo $kaffee_klein?>">
      </td><td>
          <input type="text" id="kaffee_klein_preis" name="kaffee_klein_preis" value="<?php echo $kaffee_klein_preis?>">
      </td></tr><tr><td>    
          <label for="kaffee_normal">Kaffee normal</label>
      </td><td>    
          <input type="text" id="kaffee_normal" name="kaffee_normal" value="<?php echo $kaffee_normal?>">
      </td><td>
           <input type="text" id="kaffee_normal_preis" name="kaffee_normal_preis" value="<?php echo $kaffee_normal_preis?>">
      </td></tr><tr><td>
          <label for="kaffee_gross">Kaffee groß</label>
      </td><td>  
          <input type="text" id="kaffee_gross" name="kaffee_gross" value="<?php echo $kaffee_gross?>">
      </td><td>  
          <input type="text" id="kaffee_gross_preis" name="kaffee_gross_preis" value="<?php echo $kaffee_gross_preis?>">
      </td></tr><tr><td>
          <label for="cappuccino_klein">Cappuccino klein</label>
      </td><td>      
          <input type="text" id="cappuccino_klein" name="cappuccino_klein" value="<?php echo $cappuccino_klein?>">
      </td><td>      
          <input type="text" id="cappuccino_klein_preis" name="cappuccino_klein_preis" value="<?php echo $cappuccino_klein_preis?>">
      </td></tr><tr><td>    
          <label for="cappuccino_normal">Cappuccino normal</label>
      </td><td>      
          <input type="text" id="cappuccino_normal" name="cappuccino_normal" value="<?php echo $cappuccino_normal?>">
      </td><td>    
          <input type="text" id="cappuccino_normal_preis" name="cappuccino_normal_preis" value="<?php echo $cappuccino_normal_preis?>">
      </td></tr><tr><td>    
          <label for="cappuccino_gross">Cappuccino ´groß</label>
      </td><td>      
          <input type="text" id="cappuccino_gross" name="cappuccino_gross" value="<?php echo $cappuccino_gross?>">
      </td><td>    
          <input type="text" id="cappuccino_gross_preis" name="cappuccino_gross_preis" value="<?php echo $cappuccino_gross_preis?>">
      </td></tr><tr><td>  
          <label for="espresso">Espresso</label>
      </td><td>      
          <input type="text" id="espresso" name="espresso" value="<?php echo $espresso?>">
      </td><td>    
          <input type="text" id="espresso_preis;" name="espresso_preis" value="<?php echo $espresso_preis?>">
      </td></tr><tr><td>  
          <label for="espresso_doppelt">Espresso doppelt</label>
      </td><td>      
          <input type="text" id="espresso_doppelt" name="espresso_doppelt" value="<?php echo $espresso_doppelt?>">
      </td><td>    
          <input type="text" id="espresso_doppelt_preis" name="espresso_doppelt_preis" value="<?php echo $espresso_doppelt_preis?>">
      </td></tr><tr><td>
          <label for="milchkaffee">Milchkaffee</label>
      </td><td>      
          <input type="text" id="milchkaffee" name="milchkaffee" value="<?php echo $milchkaffee?>">
      </td><td>  
          <input type="text" id="milchkaffee_preis" name="milchkaffee_preis" value="<?php echo $milchkaffee_preis?>">    
      </td></tr><tr><td>
          <label for="latte_macchiato">Latte Macchiato</label>
      </td><td>      
          <input type="text" id="latte_macchiato" name="latte_macchiato" value="<?php echo $latte_macchiato_preis?>">
      </td><td>    
          <input type="text" id="latte_macchiato_preis" name="latte_macchiato_preis" value="<?php echo $latte_macchiato_preis?>">
       </td></tr><tr><td>
          <label for="heisse_schokolade">Heiße Schokolade</label>
       </td><td>      
          <input type="text" id="heisse_schokolade" name="heisse_schokolade" value="<?php echo $heisse_schokolade?>">
       </td><td>  
          <input type="text" id="heisse_schokolade_preis" name="heisse_schokolade_preis" value="<?php echo $heisse_schokolade_preis?>">
       </td></tr><tr><td>  
          <label for="tee">Tee</label>
       </td><td>      
          <input type="text" id="tee" name="tee" value="<?php echo $tee?>">
       </td><td>  
          <input type="text" id="tee_preis" name="tee_preis" value="<?php echo $tee_preis?>">
        </td></tr>
        </table>  

        <script type="text/javascript">
    document.getElementById('milchkaffee').onfocus = function () {
        //alert('Test Milchkaffee');
        var feld = "milchkaffee";
        //alert(feld);
    };
    </script>

    <script type="text/javascript">
    document.getElementById('kaffee_klein').onfocus = function () {
        //alert('Test Milchkaffee');
        var feld = "kaffee_klein";
        //alert(feld);
    };
    </script>


    <script>
        ac.attach({
            target: document.getElementById(feld) ,
            data: "search.php",
        });
    </script>




    </form>

        </body>
    </html>

    search.php

    PHP-Code:
    <?php
    require_once "../../funktion/pdo_verbindung.php";
    $data = [];
    $stmt $pdo->prepare("SELECT ArticleNo,Text1,Text2,Price,DepositName,SpecialPrice FROM `artikel` WHERE `Text1` LIKE ?");
    $stmt->execute(["%" $_POST["search"] . "%"]);
    while (
    $row $stmt->fetch()) { $data[] = [
    "D" => $row["Text1"],"ArticleNo" => $row["ArticleNo"], "Price" => $row["Price"], "SpecialPrice" => $row["SpecialPrice"]]; }
    echo 
    count($data)=="null" json_encode($data) ;
    ?>

  • #2
    Hallo JNPANZER,
    deine Lösung findest du hier: https://www.w3schools.com/PHP/php_ajax_livesearch.asp
    Und wenn Du wirklich seit 2013 programmierst, solltest du diese Lösung auch umschreiben können
    Übrigens, dass war das erste Suchergebnis und die Suche dauerte nicht mal 30 Sekunden

    Kommentar


    • #3
      runt0m
      solche uralten Lösungen zu posten ist Senf.
      JNPANZER
      google nach fetch und lass Dir von PHP JSON zurückgeben.

      Kommentar


      • #4
        Danke ich schau mir das mal an

        Kommentar

        Lädt...
        X