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

    problema con autocomplete

    ragazzi piccolo problemuccio devo costruire un tagger e mi sto aiutando con l'autocomplete della jquery ui....ORA
    vedendo un po i vari esempio ho lavorato il codice in questa maniera

    codice:
    $(function() {
        function split( val ) {
          return val.split( /@\s*/ );
        }
        function extractLast( term ) {
          return split( term ).pop();
        }
     
        $( "#texter" )
          // don't navigate away from the field on tab when selecting an item
          .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                $( this ).data( "ui-autocomplete" ).menu.active ) {
              event.preventDefault();
            }
          })
          .autocomplete({
            source: function( request, response ) {
              $.getJSON( "list_user.php", {
                term: extractLast( request.term )
              }, response );
            },
            search: function() {
              // custom minLength
              var term = extractLast( this.value );
              if ( term.length < 2 ) {
                return false;
              }
            },
            focus: function() {
              // prevent value inserted on focus
              return false;
            },
            select: function( event, ui ) {
              var terms = split( this.value );
              // remove the current input
              terms.pop();
              // add the selected item
              terms.push( ui.item.value );
              // add placeholder to get the comma-and-space at the end
              terms.push( "" );
              this.value = terms.join( "" );
              return false;
            }
          });
      });
    ora... non so come far uscire i dati dall'list_user.php
    cioè volevo uscirmene brillantemente in questa maniera ma niente
    Codice PHP:
    <?  include 'config.php'connect(); session_start();
    $sql mysql_query("SELECT * FROM utenti") or die( mysql_error());
    while (
    $rowmysql_fetch_assoc($sql)){ 
        
    $user=$row['username'];
        echo 
    '"'.$user.'", </br>';
    }
    ?>
    Qualcuno sa come ottenere i risultati ? come lavoro la pagina php per ottenere i risultati?

  2. #2
    Bisogna usare una combinazione di utf8_encode (per i caratteri accentati o speciali) e json_encode.
    Ti posto un esempio:
    Codice PHP:
        $return_arr = array();
        
    $term $_GET["term"]; //Questo dato GET viene inviato da ui e serve per la "scrematura".
        
        
    $query="SELECT [COLOR=blue]...[/COLOR], [COLOR=purple]...[/COLOR] FROM ... WHERE ... LIKE '".$term."%' order by ... Limit 0,10";
        
    $result mysql_query($query);
        
    //loop dei dati
        
    if($result){
            while(
    $row=mysql_fetch_array($result)){
                
    array_push($return_arr,utf8_encode($row['[COLOR=blue]...[/COLOR]'])." (".$row['[COLOR=purple]...[/COLOR]'].")");
            }
        }
        
    //restituisco l'array in formato json
        
    echo json_encode($return_arr); 
    Ciao

  3. #3
    ispirandomi al tuo consiglio ho risolto in quest'altra maniera
    Codice PHP:
    <?
    include 'config.php'connect();

    $term trim(strip_tags($_GET['term']));

    $qstring "SELECT username as value,id FROM utenti WHERE username LIKE '%".$term."%'";
    $result mysql_query($qstring);

    while (
    $row mysql_fetch_array($result,MYSQL_ASSOC))
    {
            
    $row['value']=htmlentities(stripslashes($row['value']));
            
    $row['id']=(int)$row['id'];
            
    $row_set[] = $row;
    }
    echo 
    json_encode($row_set);
    ?>
    Grazie mille comunque

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.