Re Islyoung2
j essaie d'adapter ton exemple à ma base 'jecomprendspas_com_1'
avec la table shop_auteurs(ida,nom)
et shop_livres(id,titre,ida) ida est donc le lien
sur index.php j ai bien la liste avec mes auteurs mais l autre liste reste vide
je te remet le code, il doit y avoir un petit truc quelque part
Index.php
bookfind.phpCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Livres et auteurs</title> </head> <body> <script language="javascript" src="Auteur.js"></script> <?php function AuthorList() { mysql_connect("localhost","bobo","sm") or die(mysql_error()); mysql_select_db("jecomprendspas_com_1") or die(mysql_error()); $query1 = mysql_query("SELECT * FROM shop_Auteurs ORDER BY 'nom'") or die(mysql_error()); while($result = mysql_fetch_array($query1)) { echo "<option value=".$result['ida'].">".$result['nom']."</option>"; } mysql_close(); } ?> <fieldset style="width: 500px"> <legend>Liste liées</legend> Auteur :<select ida="slcAuteur" onchange="Ajax();"> <option value="-1">Aucun</option> <?php AuthorList() ?> </select> <div id="slcLivre" style="display:inline" > Livre :<select titre="slcLivre"> <option value="-1">Choisir un auteur</option> </select> </div> </fieldset> <script language="javascript"> Ajax(); //document.getElementById('slcLivre').innerHTML="<select name ='slcLivre'><option value='-1'>Choisir un auteur</option></select>" </script> </body> </html>
auteur.js:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 <?php //echo "execution bookfind.php"; $ida = $_GET['shop_auteurs']; if($ida !=-1) { mysql_connect("localhost","bobo","sm") or die(mysql_error()); mysql_select_db("jecomprendspas_com_1") or die(mysql_error()); $query1 = mysql_query("SELECT * FROM shop_livres WHERE ida = '$ida'")or die(mysql_error()); echo "Livre : <select name='slcLivre'>"; while($result = mysql_fetch_array($query1)) { echo "<option value=".$result['id'].">".$result['titr']."</option>"; } echo "</select> "; } else echo "Livre : <select name ='slcLivre'><option value='-1'>Choisir un auteur</option></select>"; ?>
voila si t'as 2 mnCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 function initAjax() { var xmlHttp; 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 ; } function Ajax() { var xmlHttp2=initAjax() var ida='-1'; //window.alert("execution ajax"); xmlHttp2.onreadystatechange=function() { //window.alert("execution onreadystatechange"); if(xmlHttp2.readyState == 4 || xmlHttp2.readyState == 0) { //window.alert("execution onreadystatechange"); // window.alert(" avant:"+idauteur); document.getElementByid('slcLivre').innerHTML = xmlHttp2.responseText; } } sel = document.getElementByida('slcAuteur'); //window.alert(sel.options[sel.selectedIndex].value); ida = sel.options[sel.selectedIndex].value; //window.alert("apres:"+idauteur); xmlHttp2.open("GET","BookFind.php?shop_auteurs="+ida,true); //window.alert("apres1:"+ida); xmlHttp2.send(null); }
merci
steph