selec di select - tutorial ajax+php

ciclare tre variabili

considerato che ho visto che luka ha un sito di ricette vorrei saoere se quanto sto facendo è un pasticcio di melanzane alla parmigiana o un pasticcio di ca....
se qualcuno ha la pazienza di guardare posto il codice

corrisponde (forse) a select.php del tutorial
Codice:
<?php

//parametri DB da fare poi include config.php
$db_host= "localhost";
$db_user= "root";
$db_password= "test";
$db_name= "provaComuni";

/* inizio costruzione array per le select dinamiche */
/*es array $dove[veneto][padova]=array(…,cadoneghe,…,padova,…, vigonza);
           $dove[veneto][vicenza]=array (…,arzignano,…,vicenza);
           $dove[trentinoaltoadige][trento]=array (ala,…,riva del garda,…,trento);
*/
$dove = array(array());//array a due dimensioni??????????

$cerca_R="select * from regioni order by regione";
$query_R= mysql_query($cerca_R);
while ($riga_R= mysql_fetch_array($query_R){ // primo while regioni
   $IDR=$riga_R[id_R];
   $REG=$riga_R[regione];
   $cerca_P= "select * province where ".$IDR." order by provincia";
   $query_P=mysql_query($cerca_P);
   while ($riga_P= mysql_fetch_array($query_P){ // secondo while province
      $IDP=$riga_P[id_p];
      $PRO=$riga_P[provincia];
      $cerca_C="select * comuni where ".$IDR." and ".$IDP." order by comune";
      $query_C=mysql_query($cerca_C);
      while ($riga_C=mysql_fetch_array($querry_C){ //terzo while comuni
         $IDC=$riga_C[id_C];
         $COM=$riga_C[comune];
         $COM = $COM.”,”.$COM; //concateno i nomi dei comuni
      }//fine terzo while
      $lung=strlen($com)-2; //numero caratteri nella stringa comuni
      $COM = substr($COM, $lung); // tolgo l’ultima virgola
      $dove['$REG']['$PRO']=array($COM);
   }// fine secondo while
}// fine primo while

/* le tabelle del DB sono

tabella regioni

id_R INT (2) UNSIGNED not nul AUTO_INCREMENT Primary key
regione VARCHAR (20) not nul

tabella province

id_P INT (2) UNSIGNED not nul AUTO_INCREMENT Primary key
id_R INT (2) UNSIGNED not nul
provincia VARCHAR (20) not nul

tabella comuni

id_C INT (3) UNSIGNED not nul AUTO_INCREMENT Primary key
id_P INT (2) UNSIGNED not nul
id_R INT (2) UNSIGNED not nul
comune VARCHAR (40) not nul

*/

?>

e questo a select.html (sempre forse)
Codice:
<html>
<head>
<script type="text/javascript">
var url = "select.php";
var what_P = "SetProvince(req.responseText)"; /*??????????*/
var what_C = "SetComuni(req.responseText)"; /*?????????? devo modificare anche su ajax?????????*/

/*su ajax ??????????????
    if (req.status == 200) 
    {
      eval(what_P); //fare eval per province e comuni?????
      eval(what_C);
    }else{
*/

function GetProvince(Regione)
{
  InviaDati("regione="+Regione);
}

function GetComuni(Provincia) /*??????devo leggere anche le province????*/
{
  InviaDati("provincia="+provincia);
}

function SetProvince(Province)
{
  var provinciaBox = document.getElementById("provincia");
  provinciaBox.options.length = 0;
  if(Province != "")
  {
    var arrProvince = Province.split(",");
    for(i = 0; i < arrProvince.length; i++)
    {
      if(arrProvince[i] != "")
      {
        provinciaBox.options[provinciaBox.options.length] = 
        new Option(arrProvince[i], arrProvince[i]);
      }
    }
  }
}

function SetComuni(Comuni) /*quindi aggiungere anche i comuni?????????????????*/
{
  var comuneBox = document.getElementById("comune");
  comuneBox.options.length = 0;
  if(Comuni != "")
  {
    var arrComuni = Comuni.split(",");
    for(i = 0; i < arrComuni.length; i++)
    {
      if(arrComuni[i] != "")
      {
        comuneBox.options[comuneBox.options.length] = 
        new Option(arrComuni[i], arrComuni[i]);
      }
    }
  }
}



</script>
<script src="ajax.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>

<form name="form1" method="post" action="scrivi.php">
  <p>Regione:<br> 
    <select onChange="GetProvince(this.options[this.selectedIndex].text)" id="regione" name="regione">
      <option value="0">-seleziona regione-</option>
      <option value="1">ABRUZZO</option>
      <option value="2">BASILICATA</option>
      <option value="3">CALABRIA</option>
      <option value="4">CAMPANIA</option>
      <option value="5">EMILIA ROMAGNA</option>
      <option value="6">FRIULI VENEZIA GIULIA</option>
      <option value="7">LAZIO</option>
      <option value="8">LIGURIA</option>
      <option value="9">LOMBARDIA</option>
      <option value="10">MARCHE</option>
      <option value="11">MOLISE</option>
      <option value="12">PIEMONTE</option>
      <option value="13">PUGLIA</option>
      <option value="14">SARDEGNA</option>
      <option value="15">SICILIA</option>
      <option value="16">TOSCANA</option>
      <option value="17">TRENTINO ALTO ADIGE</option>
      <option value="18">UMBRIA</option>
      <option value="19">VALLE D'AOSTA</option>
      <option value="20">VENETO</option>
    </select>
    <br>
    Provincia:<br> 
    <!--modificare anche la select delle province uguale a regioni??????????? -->
    <select onChange="GetComuni(this.options[this.selectedIndex].text)"id="provincia" name="provincia">
       <!-- <option value="tutte">tutte</option> ?oppzione di default? -->
    </select>
    <br>
   Comune:<br>
    <select id="comune" name="comune">
    </select

	
	
    <p>
    <input type="submit" name="Submit" value="cerca">
</p>
</form>

</body>
</html>

ciao a tutti
 

Discussioni simili