Back to top

Autore Topic: Valorizzare 2 Select da DB  (Letto 1516 volte)

Offline alpe77

  • Nuovo arrivato
  • *
  • Post: 18
    • Mostra profilo
Valorizzare 2 Select da DB
« il: 14 Dic 2007, 14:27:02 »
ciao a tutti sto cercando di fare un piccolo componente, mi sono bloccato nel gestire una select valorizzata da DB, che all'onchange dovrebbe valorizzare l'altra in base all'elemento selezionato tirando fuori i dati da DB.
Ho letto alcune cose in giro, ma non sono riuscito nell'intento, ho letto che si potrebbe o fare con AJAX o ricaricare la pagina passando il valore della prima SELECT.
ho provato questo :
pippo.html.php
Citazione
         
<script type="text/javascript">
// Create an XMLHTTPRequest object
var http;
try { http = new XMLHttpRequest(); /* e.g. Firefox */ } catch(e) {
  try { http = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */ } catch (e) {
    try { http = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */ } catch (E) {
      http = false;
}}}

// Write an event handler
/* - make the request of the server
   - check when the server says that it has completed the request, and
   - deal with the information returned by the server */
function updateData(id) {
  var myurl = "components/com_pippo/pippo.php";

  http.open("GET", (myurl + "?id=" + escape(id)), true);
  http.onreadystatechange = useHttpResponse;
  http.send(null);
}

// readyStates: 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, 4 = complete
function useHttpResponse() {
  if (http.readyState == 1) {
    showMessage('Please wait...');
  }
  else if (http.readyState == 4) {
    var textout = http.responseText;
    showMessage('Reply: ' + textout);
  }
}

// show message
function showMessage(string) {
        document.getElementById('msg').innerHTML = string;
}
//--></script>
<!-- 1° Select    riempita a mano (riempire la prima select con DB non è un problema -->            
Scelta: <select name="" onchange="(this.options[this.selectedIndex].value=='')?i=0:updateData(this.options[this.selectedIndex].value);">
  <option value="" selected="selected"> </option>
  <option value="1998">1998</option>
  <option value="1999">1999</option>
  <option value="2000">2000</option>
</select>
<!-- non ho creato ancora la 2° select ho provato solo se rispondeva l'altra pagina -->
<p id="msg"></p>
</body>
<?php }   ?>


e questo è l'altro file pippo.php, qui in realtà all'interno dovrei cercare di fare la connessione al DB e di valorizzare l'altra select, ma dato che questo file non deve essere integrato nel sito (altrimenti al richiamo richiamerebbe tutto il sito e non solo la cosa che mi interessa), non mi vede la variabile $database. Come posso fare?
Citazione
header('Cache-Control: no-cache');
 header('Pragma: no-cache');
 
 switch ($_GET['id']) {
  case 1998:
   echo '1 selected';
   break;
  case 1999:
   echo '2 selected';
   break;
  case 2000:
   echo '3 selected';
   break;
  default:
   echo 'No id was sent to the server.';
 }
?>

C'è qualcuno che mi può aiutare??

Offline alpe77

  • Nuovo arrivato
  • *
  • Post: 18
    • Mostra profilo
Re: Valorizzare 2 Select da DB
« Risposta #1 il: 16 Dic 2007, 21:20:57 »
non c'è proprio nessuno che mi possa aiutare??
Vi prego sto impazzendo sto a tanto dalla soluzione...
Ciao e grazie a chi mi voglia rispondere.

 



Web Design Bolzano Kreatif