Salve a tutti, io ho una pagina index.html cosi' :
<HTML>
<HEAD>
<script src="selectuser.js"></script>
</HEAD>
<BODY>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="" selected="selected">== Please choose a currency ==</option>
<option value="asc">ASC</option>
<option value="desc">desc</option>
</select>
</form>
<p id="txtHint"></p>
</BODY>
</HTML>
e una pagina selectuser.js:
e una pagina getuser.phpvar xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHt tp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
La mia domanda é:<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '1234');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("user", $con);
$sql="SELECT * FROM users order by id ".$q."";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Indirizzo</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['nome'] . "</td>";
echo "<td>" . $row['cognome'] . "</td>";
echo "<td>" . $row['indirizzo'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
come faccio a visualitzzare la tabella MYSQL anche in index.html, poiché finché l'utente non sceglie tra ordinamento ASC o DESC non viene visualizzata alcuna tabella.
Grazie dell'attenzione.![]()