<?php
$nazione = $_POST['nazione'];
$regione = $_POST['regione'];
$citta = $_POST['citta'];
if ($nazione) $id=1;
if ($regione) $id=2;
if ($citta) $id=3;
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "1234";
$dbname = "realestate";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
?>
<html>
<head><title></title></head>
<body>
<form id="test" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<select name="nazione" onchange="document.forms[0].submit()">
<option value=""></option>
<?php
$result=mysql_db_query($dbname,"select distinct(country) from addresses where detail='1'");
while(list($country)=mysql_fetch_array($result)){
if ($nazione == $country) { echo "<option value=\"$country\" selected=selected>$country</option> \n"; } else
{ echo "<option value=\"$country\">$country</option> \n"; }
}
?>
</select>
<? if ($id==1) { ?>
<select name="regione" onchange="document.forms[0].submit()">
<option value=""></option>
<?
$result=mysql_db_query($dbname,"SELECT distinct(state) FROM addresses WHERE detail='1' and country LIKE '$nazione' ");
while(list($state)=mysql_fetch_array($result)){
if ($regione==$state) { echo "<option value=\"$state\" selected=selected>$state</option> \n" ; }
else
{
echo "<option value=\"$state\" >$state</option> \n" ;
}
}
?>
</select>
<? }
else { ?>
<select name="regione" size="1" onchange="document.forms[0].submit()">
<option value=""></option>
<?
if ($regione=='') {
echo "<option value=\"\" selected=selected>Select a Country</option> \n" ;
}
else
{
echo "<option value=\"$regione\" selected=selected>".$regione."</option> \n" ;
}
?>
</select>
<? } ?>
<? if ($id==2) { ?>
<option value=""></option>
<select name="citta" onchange="document.forms[0].submit()">
<?
$result=mysql_db_query($dbname,"SELECT distinct(city) FROM addresses WHERE
detail='1' and state LIKE '$regione' ");
while(list($city)=mysql_fetch_array($result)){
echo "<option value=\"$city\" >$city</option> \n" ;
}
?>
</select>
<? } else { ?>
<select name="citta" size="1" onchange="document.forms[0].submit()">
<option value=""></option>
<?
if ($citta=='') {
echo "<option value=\"\" selected=selected>Select a Region</option> \n" ;
}
else
{
echo "<option value=\"$citta\" selected=selected>".$citta."</option> \n" ;
}
?>
</select>
<? } ?>
</form>
</body>
</html>