ciao ragazzi,
vi scrivo perchè sto impazzendo. sto cercando semplicemente di realizzare un menu a cascata con regione, provincia e comuni da un esempio che trovato in rete. il mio problema è che i dati li prendo da un vecchi database che non posso toccare ed ha due tabelle la prima tblregioni con idregioni e regione la seconda (delle province) tbl capoluoghi con idcapoluoghi e idregione.

posto il codice qui sotto

index.php

<head>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
// Select Province e Comuni dalla Regione.
function selProvCom(idRegion) {
// Seleziono province di questa regione.
$.get("select_abitativa.php", { regionid: idRegion, requestItems: 'tblcapoluoghi'},
function(dataProvince){
$("select[id='tblcapoluoghi']").empty();
var options = '<option value="">-- seleziona --</option>';
var arrayProvince = dataProvince.split( '||');
for (var i = 1; i < arrayProvince.length; i++) {
var provincia = arrayProvince[i].split( /,/);
options += '<option value="' + Capoluogo[0] + '">' + Capoluogo[1] + '</option>';
}
$("select[id='province']").html(options);
});
// Seleziono comuni di questa regione.
$.get("select_abitativa.php", { regionid: idRegion, requestItems: 'comuni'},
function(dataComuni){
$("select[id='city']").empty();
var options = '<option value="">-- seleziona --</option>';
var arrayComuni = dataComuni.split( '||');
for (var i = 1; i < arrayComuni.length; i++) {
var comune = arrayComuni[i].split( /,/);
options += '<option value="' + comune[0] + '">' + comune[1] + '</option>';
}
$("select[id='city']").html(options);
});
}

// Select Comuni dalla Provincia.
function selCom(idProvincia) {
// Seleziono comuni di questa provincia.
$.get("select_abitativa.php", { provinciaid: idProvincia, requestItems: 'comuni'},
function(dataComuni){
$("select[id='city']").empty();
var options = '<option value="">-- seleziona --</option>';
var arrayComuni = dataComuni.split( '||');
for (var i = 1; i < arrayComuni.length; i++) {
var comune = arrayComuni[i].split( /,/);
options += '<option value="' + comune[0] + '">' + comune[1] + '</option>';
}
$("select[id='city']").html(options);
});
}
</script>


</head>



<?php
//connessione al database
$db_username = 'xxxx';
$db_password = '0xxxx';
$db_host = 'xxxxx8';
$link = @mysql_connect("$db_host", "$db_username", "$db_password") or die("Errore connessione: ". mysql_error());

//selezione del db
$dbw = mysql_select_db('xxxx') or die("Errore apertura database: " . mysql_error());
?>




<label for="region">Regione:</label>

<select id="region" name="region" onchange="selProvCom(this.value);">
<option value="" selected="selected">-- seleziona --</option>
<?php
// Collegamento ad database.

// Query selezione tutte le regioni.
$sql = "select * from tblregioni order by Regione";

// Eseguo la query.
$result = mysql_query($sql, $link);
while($region = mysql_fetch_array($result)) {
?>
<option value="<?php echo $region['IDRegione']; ?>"><?php echo $region['Regione']; ?></option>
<?php
}
?>
</select>
</p>



<label for="tblcapoluoghi">Provincia:</label>

<select id="tblcapoluoghi" name="tblcapoluoghi" onchange="selCom(this.value);">
<option value="" selected="selected">-- seleziona --</option>
<?php

// Query selezione tutte le province.
$sql = "select * from tblcapoluoghi order by Capoluogo";

// Eseguo la query.
$result = mysql_query($sql, $link);
while($tblcapoluoghi = mysql_fetch_array($result)) {
?>
<option value="<?php echo $tblcapoluoghi['IDCapoluogo']; ?>"><?php echo $tblcapoluoghi['Capoluogo']; ?></option>
<?php
}
?>
</select>
</p>



<label for="city">Città:</label>

<select id="city" name="city">
<option value="" selected="selected">-- seleziona --</option>
</select>
<input type="submit" name="submit" value="Invia" />

</p>



di seguito il codice per select_abitativa.php


<?php
//connessione al database
$db_username = 'xxxx';
$db_password = 'xxx';
$db_host = 'xxx';
$link = @mysql_connect("$db_host", "$db_username", "$db_password") or die("Errore connessione: ". mysql_error());

//selezione del db
$dbw = mysql_select_db('xxx') or die("Errore apertura database: " . mysql_error());
?>








<?php
// Seleziona Province e Comuni.

if (isset($_GET['regionid']) and is_numeric($_GET['regionid'])) {
if (isset($_GET['requestItems']) and $_GET['requestItems']==='tblcapoluoghi') {
$regionID = intval($_GET['regionid']);
$query = <<<EOQ
echo '$regionID';
SELECT *
FROM tblcapoluoghi
WHERE IDRegione = '$regionID'
ORDER BY Capoluogho
EOQ;
$result = mysql_query($query, $link);
$returnProvince = '';
while ($row = mysql_fetch_array($result)) {
$returnProvince .= "||".$row['IDCapoluogo'].",".$row['Capoluogo'];
$prova = $row['IDCapoluogo'];
echo $prova;
}
print_r($returnProvince);
}
else if (isset($_GET['requestItems']) and $_GET['requestItems']==='comuni') {
$regionID = intval($_GET['regionid']);
$query = <<<EOQ
SELECT *
FROM comuni
WHERE id_regione = '$regionID'
ORDER BY comune
EOQ;
$result = mysql_query($query, $conn);
$returnComuni = '';
while ($row = mysql_fetch_array($result)) {
$returnComuni .= "||".$row['id'].",".$row['comune'];
}
print_r($returnComuni);
}
}
else if (isset($_GET['provinciaid']) and is_numeric($_GET['provinciaid'])) {
if (isset($_GET['requestItems']) and $_GET['requestItems']==='comuni') {
$provinciaID = intval($_GET['provinciaid']);
$query = <<<EOQ
SELECT *
FROM comuni
WHERE id_provincia = '$provinciaID'
ORDER BY comune
EOQ;
$result = mysql_query($query, $conn);
$returnComuni = '';
while ($row = mysql_fetch_array($result)) {
$returnComuni .= "||".$row['id'].",".$row['comune'];
}
print_r($returnComuni);
}
}
?>

la primaselect e la seconda me la carica ma non riesco a collegarle (regioni e province per il momento i comuni non li ho toccati) mi date una mano? grazie