Ankündigung

Einklappen
Keine Ankündigung bisher.

PHP & AutoSuggest Funktion

Einklappen

Neue Werbung 2019

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

  • PHP & AutoSuggest Funktion

    Hallo Leute. Ich hoffe ich werde für meine Frage hier nicht gleich gesteinigt...

    Ich baue gerade eine Seite mit gewünschter AutoSuggest Suchfunktion. Dafür habe ich folgendes Script genutzt: Ajax Auto Suggest v.2 : CSS . XHTML . Javascript . DOM : Brand Spanking New

    Es funktioniert soweit alles, nur dass ich die gesuchten Felder zwar anklicken kann aber sie verschwinden sofort aus meiner Leiste und nix passiert. Ich würde gern die Suchergebnisse mit einem Link versehen, sodass Suche als Ergebnis auf einer neuen Seite erscheint.


    Der derzeitige PHP-Code sieht wie folgt aus:
    PHP-Code:
    <?php

    /*
    note:
    this is just a static test version using a hard-coded countries array.
    normally you would be populating the array out of a database

    the returned xml has the following structure
    <results>
      <rs>foo</rs>
      <rs>bar</rs>
    </results>
    */

      
    $aUsers = array(
     
    /*1*/ "Friedrichstrasse 115",
    /*2*/ "Königstraße 12",
    /*3*/ "Leopoldstr. 113",
    /*4*/ "Berlin",
    /*5*/ "Düsseldorf"
      
    );
     
     
      
    $aInfo = array(
    /*1*/   "Berlin, Mitte",
    /*2*/ "Düsseldorf, Oberbilk",
    /*3*/ "München, Sendling",
    /*4*/ "Deutschland",
    /*5*/ "Deutschland"
      
    );
     
     
      
    $input strtolower$_GET['input'] );
      
    $len strlen($input);
      
    $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
     
     
      
    $aResults = array();
      
    $count 0;
     
      if (
    $len)
      {
        for (
    $i=0;$i<count($aUsers);$i++)
        {
          
    // had to use utf_decode, here
          // not necessary if the results are coming from mysql
          //
          
    if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
          {
            
    $count++;
            
    $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
          }
         
          if (
    $limit && $count==$limit)
            break;
        }
      }
     
     
     
     
     
      
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
      
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); // always modified
      
    header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
      
    header ("Pragma: no-cache"); // HTTP/1.0
     
     
     
      
    if (isset($_REQUEST['json']))
      {
        
    header("Content-Type: application/json");
     
        echo 
    "{\"results\": [";
        
    $arr = array();
        for (
    $i=0;$i<count($aResults);$i++)
        {
          
    $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
        }
        echo 
    implode(", "$arr);
        echo 
    "]}";
      }
      else
      {
        
    header("Content-Type: text/xml");

        echo 
    "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
        for (
    $i=0;$i<count($aResults);$i++)
        {
          echo 
    "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
        }
        echo 
    "</results>";
      }
    ?>

    Wie kann ich die einzelnen Punkte mit einem href verlinken?

    Das Suchfeld sieht so aus:
    Code:
    <form method="get" action="" class="asholder">
                            <fieldset><input type="submit" id="searchBoxBtn" value="Suchen" /><input id="searchBox" value="" type="text" /></fieldset>
                        </form>

    Und Javascript so:
    Code:
    <script type="text/javascript">
      var options_xml = {
        script:"test.php?",
        varname:"input"
      };
      var as_xml = new bsn.AutoSuggest('searchBox', options_xml);
    </script>

    Ich hätte es gern so wie in diesem Beispiel:
    UKFindit - UK Search Engine

    Suchen, anklicken und verlinkt werden.


    Danke für Eure Hilfe!!!
Lädt...
X