Ragazzi potete darmi un aiuto?
Dal seguente link:
link ho scaricato lo script che fa al caso mio.
Di default ha solo una input text e sono riuscito ad espanderlo a due e quindi magari a tre o più...
L'unico problema: visto che interroga il database vorrei anche fargli passare la tabella in un modo da aver tutti in un file, mi spiego meglio:
codice:
<div class="campo">Sistema operativo:</div>
<input type="text" id="ricerca" name="ricerca"/>
<div id="suggerimenti_ricerca" class="boxsuggerimenti"></div>
<script type="text/javascript">new Ajax.Autocompleter("ricerca", "suggerimenti_ricerca", "cerca.php", "sistemaoperativo", {minChars: 1});</script>
<input type="text" id="ricerca1" name="ricerca1"/>
<div id="suggerimenti_ricerca" class="boxsuggerimenti"></div>
<script type="text/javascript">new Ajax.Autocompleter("ricerca1", "suggerimenti_ricerca", "cerca.php", "sistemaoperativo", {minChars: 1});</script>
Il file "cerca.php" è così strutturato:
Codice PHP:
<?
if(isset($_POST['ricerca'])){$ricerca=$_POST['ricerca'];}else{$ricerca="";}
if(isset($_POST['ricerca1'])){$ricerca=$_POST['ricerca1'];}else{$ricerca1="";}
$conn=mysql_connect("localhost","root","") or die (mysql_error());
mysql_select_db("tesi") or die (mysql_error());
$query="select nome from sistemaoperativo where nome like '%$ricerca%' order by nome";
$result = mysql_query ($query, $conn) or die(mysql_error());
$ArrayRisultati=Array();
while ($risultati = mysql_fetch_array ($result)){
array_push($ArrayRisultati,$risultati) ;
}
echo "<ul>";
for($a=0;$a<count($ArrayRisultati);$a++){
echo "[*]".$ArrayRisultati[$a]['nome']."";
}
echo "[/list]";
?>
poi tra tutti i js secondo me da modificare è la seguente classe:
codice:
Ajax.Autocompleter = Class.create(Autocompleter.Base, {
initialize: function(element, update, url, table, options) {
this.baseInitialize(element, update, table, options);
this.options.asynchronous = true;
this.options.onComplete = this.onComplete.bind(this);
this.options.defaultParams = this.options.parameters || null;
this.url = url;
this.table = table;
},
getUpdatedChoices: function() {
this.startIndicator();
var entry = encodeURIComponent(this.options.paramName) + '=' +
encodeURIComponent(this.getToken());
this.options.parameters = this.options.callback ?
this.options.callback(this.element, entry) : entry;
if(this.options.defaultParams)
this.options.parameters += '&' + this.options.defaultParams;
new Ajax.Request(this.url, this.table, this.options);
},
le tre voci table le ho aggiunte io, ma non vanno!
Vedete che nel file cerca.php interroga la tabella sistemaoperativo? Come faccio a passar nell'input text anche il nome della tabella da interrogare?