Voila les table de ma base de donnee:
create table domaine(
idDomaine int(3) primary key ,
DesDomaine varchar(70)
);
create table Sousdomaine(
idSousDomaine int(3) primary key,
DesSousDomaine varchar(70),
idDomaine int(3),
constraint fk_Domaine_Sousdomaine foreign key (idDomaine) references domaines(idDomaine)
);
create table SousSousdomaine(
idSousSousDomaine int(3) primary key,
DesSousSousDomaine varchar(70),
idSousDomaine int(3),
constraint fk_SousDomaine_SousSousdomaine foreign key (idSousDomaine ) references Sousdomaines(idSousdomaine )
);
je desire creer un formulaire qui permet a l'utilisateur de choisir un domaine dans une liste de choix comportant plusieurs domaines.En selectionant un domaine,les sous domaines qui lui appartient s'affiche dans une liste de choix pour arriver a entrer un sous sous domaine manuellement . voici mon code :
<?php
session_start();
// connexion au serveur
mysql_connect("localhost","root","");
mysql_select_db("question");
?>
<html>
<head>
<title>.:: Sous Domaines ::.</title>
<script language="JavaScript">
function ajout()
{
if(document.maforme.sdom.value == '')
alert('entrer le nom de la nouvelle entrée puis valider');
else {
document.maforme.action="nouv_SousDomaine.php";
// document.maforme.submit();
}
}
function annul() {
document.maforme.ajouter.style.visibility = "visible";
document.maforme.valider.style.visibility = "hidden";
}
function modif(cod_type,sdom) {
document.maforme.cod_type.value = cod_type;
document.maforme.sdom.value = sdom;
document.maforme.ajouter.style.visibility = "hidden";
document.maforme.valider.style.visibility = "visible";
}
function valid() {
if(document.maforme.sdom.value == '')
alert('entrer le nouveau nom puis valider');
else
{
document.maforme.action="modif_SousDomaine.php";
document.maforme.submit();
}
}
function supp(cod_type,sdom) {
question = confirm("Vous êtes sur le point de supprimer cet élément.");
if (question !="0"){
document.maforme.cod_type.value = cod_type;
document.maforme.sdom.value = sdom;
document.maforme.action="supp_SousDomaine.php";
document.maforme.submit();
}
}
</script>
<style type="text/css">
<!--
.style4 {
font-family: "Courier New", Courier, monospace;
font-weight: bold;
}
-->
</style>
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style5 {color: #00FF00}
.style7 {
color: #666666;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
.style10 {font-size: 12px; font-family: "Courier New", Courier, monospace; }
-->
</style>
</head>
<body >
<a href="administrateur.php" target="_self">Acceuil</a>
<table width="100%" align="center" border="0">
<tr>
<table width="100%" align="center" border="0">
<tr>
<td height="206" align="center" valign="top">
<form name="maforme" method="post">
<table width="100%" height="31" border="0" align="center" bgcolor="#000000" class="ablue">
<tr>
<td width="37%" height="27" class="style5">Domaines
<select name="dom" size="1" id="dom" onchange="submit()">
<?php
$sql1 = "SELECT * FROM domaines";
$rs1 = mysql_query($sql1) or die('Erreur de requête de base de données.');
while($malign1 = mysql_fetch_array($rs1))
{
?>
<option value="<?php echo $malign1["idDomaine"];?>">
<?php echo $malign1["DesDomaine"]; ?>
</option>
<?php
}
?>
</select>
</td>
<td width="37%" height="27" class="style5">Sous Domaine<font size="2">
<input name="sdom" type="text" class="input" id="sdom" size="40" maxlength="120">
<span style="visibility:hidden;">
<input name="cod_type" id="cod_type" type="hidden">
</span>
</td>
<td width="20%">
<input name="ajouter" type="submit" id="ajouter" value="Ajouter"onClick="ajout()">
<input name="valider" type="submit" value="Valider" id="valider" style="visibility:hidden" onClick="valid()">
<input name="annuler" type="reset" id="annuler" value="Rétablir" onClick="annul()">
</td>
</tr>
</table>
</form>
<table border="1" width="100%">
<tr bgcolor="#CCCCCC">
<th width="15%" bgcolor="#CCCCCC"><strong>Domaine </strong></th>
<td width="60%" bgcolor="#CCCCCC">Sous Domaines</td>
<th width="21%" bgcolor="#CCCCCC">Opérations</th>
</tr>
<tbody id="offTblBdy">
<?php
$_SESSION['dom'] = $_POST['dom'];
$x= $_SESSION['dom'];
echo $x;
$monsql="select * from domaines d, sousdomaines sd where d.idDomaine = sd.idDomaine and d.idDomaine ='.$x.'";
if($monrs = mysql_query($monsql)) {
while($maligne = mysql_fetch_array($monrs)) {
?>
<tr>
<td><?php echo $maligne["idDomaine"]; ?> </td>
<td><?php echo $maligne["DessousDomaine"]; ?></td>
<td align="center">
<label>
<input name="modifier" type="button" class="input2" id="modifier" value="Modifier"
onClick="modif('<?php echo $maligne["idSousDomaine"]; ?>',
'<?php echo $maligne["DessousDomaine"]; ?>')" >
<input name="supprimer" type="button" class="input2" id="supprimer"
onClick="supp('<?php echo $maligne["idSousDomaine"]; ?>')" value="Supprimer">
</label>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</body>
</html>