Ciao sono luigi, scusate il disturbo.
Vi scrivo perchè sul forum non ho trovato soluzioni dirette per il mio caso e non sono riuscito ad addattare nessuna di quelle trovate.
Ho necessità di visualizzare in un menù a tendina una lista di nomi di dipendenti (presenti nel db) e di sceglierne uno e visualizzare ogni info riguardante ogni singolo dipendente.
Ho una tabella in un database con più colonne, organizato così: https://ibb.co/gtFbG2M
Ho scritto due pagine. una php con il menù e la possibilità di scegliere e un altra con lo script php richiamato dalla homepage per far visualizzare tutte le info in una tabella.
Il codice della home è questo :
mentre il codice dello script è il seguente :codice:<html> <head> <script language="Javascript"> var xmlhttp; function mostraInfo(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="script.php"; url=url+"?q="+str; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("info").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> <?php $database = "test"; $con = mysql_connect("####","####","####")or die ('Errore connessione'); mysql_select_db($database, $con); ?> </head> <body> <form id="form1" name="form1" method="post" action="onChange="mostraInfo(this.value)"> <table width="500px" border="0" cellpadding="5"> <tr> <td>Dipendente</td> <td> <select> <?php $query="SELECT DISTINCT dipendente FROM TabellaOrari ORDER BY dipendente ASC"; $result =mysql_query($query); while ($row = mysql_fetch_assoc($result)){ echo "<option value='".$row['dipendente']."'>".$row['dipendente']."</option>"; } ?> </select> </td> </tr> </tab le> </form> </body> </html>
Ho necessità di autoaggiornare la pagina quindi senza farla cambiare.codice:<?php $q=$_GET["q"]; $database = "test"; $con = mysql_connect("####","####","####")or die ('Errore connessione'); mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM TabellaOrari WHERE id = ".$q.""); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } echo "<table border='1'> <tr> <th>Dipendente</th> <th>Commessa</th> <th>Data</th> <th>Ore Ordinarie</th> <th>Ore Straordinarie</th> <th>ID Funzione</th> <th>Gruppo1</th> <th>Gruppo2</th> <th>Gruppo3</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['dipendente'] . "</td>"; echo "<td>" . $row['commessa'] . "</td>"; echo "<td>" . $row['data'] . "</td>"; echo "<td>" . $row['ore ordinarie'] . "</td>"; echo "<td>" . $row['ore straordinarie'] . "</td>"; echo "<td>" . $row['id_funzione'] . "</td>"; echo "<td>" . $row['gruppo1'] . "</td>"; echo "<td>" . $row['gruppo2'] . "</td>"; echo "<td>" . $row['gruppo3'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?>
Il problema è al momento che non visualizzo il nome dei dipendenti e non ho la possibilità di scegliere il dipendente e quindi, dopo averlo scelto, di mandare il paramentro alla funzione.
presente nella home per farlo svolgere allo script.codice:function mostraInfo(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="script.php"; url=url+"?q="+str; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); }
In attesa di una Vostra risposta, vi ringrazio anticipatamente.
--
Luigi

					
					
					
						
  Rispondi quotando
			