Ciao, grazie mille per l'aiuto, ma ho ancora qualche dubbio... innanzitutto tu mi ha scritto:
"nel codice che hai modificato non viene creato un file XML come risultato di una query ma quello che viene restituito è plain text."
Come faccio a creare il file xml dalla query?
Ti posto qui il codice nuovo:
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Post</title>
</head>
<body>
<div id="xmldata"></div>
<script type="text/javascript">
function readyAJAX() {
try {
return new XMLHttpRequest();
} catch(e) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
return "Hai bisogno di un altro browser.";
}
}
}
}
function mostraInfo(data)
{
var requestObj = readyAJAX();
var url = "mostra_utenti.php";
var params = "q=" + data;
requestObj.open("POST",url,true);
requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
requestObj.send(params);
requestObj.onreadystatechange = function() {
if (requestObj.readyState == 4) {
if (requestObj.status == 200) {
alert(requestObj.responseText);
} else {
alert(requestObj.statusText);
}
}
}
}
</script>
<form>
Seleziona Dipendente:
<select name="users" onChange="mostraInfo(this.value)">
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
//Seleziono quelli che sono i dipendenti
$connessione = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $connessione);
$query = "SELECT * FROM user ";
$result = mysql_query($query);
while($riga = mysql_fetch_array($result)){
echo "<option value='$riga[user_id]'>$riga[user_firstname] $riga[user_lastname]</option>";
}
?>
</select>
</form>
<div id="info"></div>
</body>
</html>
e l'altro file è
Codice PHP:
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
$q=$_POST['q'];
$con = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $con);
$sql="SELECT *
FROM user
WHERE user_id = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['user_firstname'] . "</td>";
echo "<td>" . $row['user_lastname'] . "</td>";
echo "<td>" . $row['user_username'] . "</td>";
echo "<td>" . $row['user_password'] . "</td>";
echo "<td>" . $row['user_email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Ma non funziona comunque...
Tu mi hai detto che:
"devi aggiungere nel codice JS l'istruzione che inserirà l'HTML, di ritorno dal file mostra_utenti.php, nel div "info" che è presente in fondo al file."
come faccio?
Con questo codice sopra se provo con firefox o IE8 quando seleziono il nome mi viene una finestra di alert, esattamente quella che nel codice è questa:
codice:
alert(requestObj.responseText);
con dentro scritto:
lo user_id corretto in base a che nome scelgo, seguito da questo codice:
codice:
"<table border='1'><tr> <th>Nome</th> <th>Cognome</th> <th>Username</th> <th>Password</th> <th>Email</th> </tr>";
e poi tra vari tr e td i giusti campi user_firstname, user_lastname ecc...
Quindi accede al database e li prende correttamente, funziona anche correttamente, ma stampando il tutto su una finsestra di alert, ovviamente non vede la tabella che ho fatto con php dentro all'echo del secondo file.... Consigli?
Scusa per il disturbo, ti ringrazio in anticipo
Saluti
Andrea