Précédent   Forum des professionnels en informatique > PHP > Langage > Formulaires
Formulaires Forum d'entraide sur les formulaires avec PHP. Avant de poster -> FAQ formulaires, Cours de formulaires et Sources de formulaires
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 26/01/2008, 16h07   #1
Membre du Club
 
Avatar de Lenezir
 
Inscription : février 2006
Messages : 129
Détails du profil
Informations personnelles :
Âge : 25

Informations forums :
Inscription : février 2006
Messages : 129
Points : 56
Points : 56
Par défaut Doublon dans une liste déroulante

Salut ^^
Grâce à l'aide de Gats (http://www.developpez.net/forums/sho...d.php?t=479928), j'ai réussi à afficher un champ bien spécifique d'une liste déroulante lors de la modification de la fiche d'un employé de ma boîte.
En effet, j'avais la liste des employés dans un tableau avec en face de chacun d'un un bouton de modification, qui m'ouvrait un formulaire reprenant les données déjà inscrites sur l'employé, y compris la fonction de l'employé qui se trouve dans une liste déroulante.
Mais maintenant, j'ai un nouveau problème suite à ça.
Quand j'édite un employé, j'ai bien sa fonction, mais dans la liste elle apparaît deux fois.
Voici le code complet :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$fonctions_brute = mysql_query("SELECT fonction FROM fonction ORDER BY fonction ASC") or die(mysql_error());
<select name="fonctions">
<?php
	while($fonctions = mysql_fetch_array($fonctions_brute))
	{
		if($fonctions['fonction'] == $_GET['fonction'])
		{
			$selectedf = ' selected';
?>
			<option name="fonctions" value="<?php echo $fonctions['fonction']; ?>"<?php echo $selectedf; ?>><?php echo $fonctions['fonction']; ?></option>
<?php
		}
?>
		<option name="fonctions" value="<?php echo $fonctions['fonction']; ?>"><?php echo $fonctions['fonction']; ?></option>
 
<?php
	}
?>
</select>
D'un côté ça me semble logique.
Je demande dans le if à ce qu'on m'affiche et sélectionne la fonction du gars, et en dehors qu'on me réaffiche toutes les fonctions y compris celle déjà affichée.
Alors j'ai voulu faire une restriction :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$fonctionr_brute = mysql_query("SELECT fonction FROM fonction WHERE fonction != '".$_GET['fonction']."'") or die(mysql_error());
$fonctionr = mysql_fetch_array($fonctionr_brute);
<select name="fonctions">
<?php
	while($fonctions = mysql_fetch_array($fonctions_brute))
	{
		if($fonctions['fonction'] == $_GET['fonction'])
		{
			$selectedf = ' selected';
?>
			<option name="fonctions" value="<?php echo $fonctions['fonction']; ?>"<?php echo $selectedf; ?>><?php echo $fonctions['fonction']; ?></option>
<?php
		}
?>
		<option name="fonctions" value="<?php echo $fonctionr['fonction']; ?>"><?php echo $fonctionr['fonction']; ?></option>
 
<?php
	}
?>
</select>
Dans la requête je veux qu'on prenne toutes les entrées sauf celle déjà affichée, et je l'ai mise dans le 2è option.
Mais à la place du résultat attendu, il m'affiche toute une liste portant le même nom (60 fois la même fonction).
Est-ce que vous auriez une idée ?
Merci de votre aide
Lenezir est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/01/2008, 16h26   #2
Membre du Club
 
Avatar de Lenezir
 
Inscription : février 2006
Messages : 129
Détails du profil
Informations personnelles :
Âge : 25

Informations forums :
Inscription : février 2006
Messages : 129
Points : 56
Points : 56
Ah j'ai à moitié résolu mon problème !
Voici le nouveau code :
Code :
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
	// Connection à la base de données
	session_start();
	mysql_connect("localhost", "root", "");
	mysql_select_db("intranet");
	// Liste du personnel
	$liste_brute = mysql_query("SELECT * FROM personnel ORDER BY num_int ASC") or die(mysql_error());
	// Liste des services
	$services_brute = mysql_query("SELECT service FROM service ORDER BY service ASC") or die(mysql_error());
	$fonctions_brute = mysql_query("SELECT fonction FROM fonction ORDER BY fonction ASC") or die(mysql_error());
	// Requêtes
	$servicer_brute = mysql_query("SELECT service FROM service".$serv_where." ORDER BY service ASC") or die(mysql_error());
	//$servicer = mysql_fetch_array($servicer_brute);
	$fonctionr_brute = mysql_query("SELECT fonction FROM fonction".$fonc_where." ORDER BY fonction ASC") or die(mysql_error());
	//$fonctionr = mysql_fetch_array($fonctionr_brute);
	// Authorisation de modification
	$modif = $_GET['modif'];
?>
<html>
	<head>
	</head>
	<body>
		<table border=1> <!-- En tête de tableau -->
			<tr>
				<th>Service</th>
				<th>Fonction</th>
				<th>Nom</th>
				<th>N° Int</th>
				<th>N° Ext</th>
				<th>N° Port</th>
				<th>N° Fax</th>
				<th>Email</th>
			</tr>
			<?php
				while($liste = mysql_fetch_array($liste_brute)) // Liste du personnel
				{
			?>
					<tr>
						<td><?php echo $liste['service']; ?></td>
						<td><?php echo $liste['fonction']; ?></td>
						<td><?php echo $liste['nom']; ?></td>
						<td><?php echo $liste['num_int']; ?></td>
						<td><?php echo $liste['num_ext']; ?></td>
						<td><?php echo $liste['num_port']; ?></td>
						<td><?php echo $liste['num_fax']; ?></td>
						<td><?php echo $liste['email']; ?></td>
						<td><a href="./index.php?page=repertoire&modif=1&IdServ=<?php echo $liste['IdServ']; ?>&service=<?php echo $liste['service']; ?>&fonction=<?php echo $liste['fonction']; ?>&nom=<?php echo $liste['nom']; ?>&num_int=<?php echo $liste['num_int']; ?>&num_ext=<?php echo $liste['num_ext']; ?>&num_port=<?php echo $liste['num_port']; ?>&num_fax=<?php echo $liste['num_fax']; ?>&email=<?php echo $liste['email']; ?>">Modifier</a></td>
					</tr>
			<?php
				}
			?>
		</table>
		<br/>
		<?php
			if($modif == 1) // Si la modification a été authorisée, formulaire contenant les données pré-enregistrées
			{
		?>
				<form method="GET" action="./repertoire/modification.php">
					<table align="center">
						<tr><td>Service :</td><td>
							<select name="services">
							<?php
								while($services = mysql_fetch_array($services_brute) && $servicer = mysql_fetch_array($servicer_brute))
								{
									if($services['service'] == $_GET['service'])
									{
										$selecteds = ' selected';
										$serv_where = " WHERE service != '".$_GET['service']."'";
							?>
										<option name="services" value="<?php echo $services['service']; ?>"<?php echo $selecteds; ?>><?php echo $services['service']; ?></option>
							<?php
									}
							?>
									<option name="services" value="<?php echo $servicer['service']; ?>"><?php echo $servicer['service']; ?></option>
							<?php
								}
							?>
							</select>
						</td></tr>
						<tr><td>Fonction :</td><td>
							<select name="fonctions">
							<?php
								while($fonctions = mysql_fetch_array($fonctions_brute) && $fonctionr = mysql_fetch_array($fonctionr_brute))
								{
									if($fonctions['fonction'] == $_GET['fonction'])
									{
										$selectedf = ' selected';
										$fonc_where = " WHERE fonction != '".$_GET['fonction']."'";
							?>
										<option name="fonctions" value="<?php echo $fonctions['fonction']; ?>"<?php echo $selectedf; ?>><?php echo $fonctions['fonction']; ?></option>
							<?php
									}
							?>
									<option name="fonctions" value="<?php echo $fonctionr['fonction']; ?>"><?php echo $fonctionr['fonction']; ?></option>
 
							<?php
								}
							?>
							</select>
						</td></tr>
						<tr><td>Nom :</td><td><input type="text" name="nom" value="<?php echo $_GET['nom']; ?>" /></td></tr>
						<tr><td>N° Int :</td><td><input type="text" name="num_int" value="<?php echo $_GET['num_int']; ?>" /></td></tr>
						<tr><td>N° Ext :</td><td><input type="text" name="num_ext" value="<?php echo $_GET['num_ext']; ?>" /></td></tr>
						<tr><td>N° Port :</td><td><input type="text" name="num_port" value="<?php echo $_GET['num_port']; ?>" /></td></tr>
						<tr><td>N° Fax :</td><td><input type="text" name="num_fax" value="<?php echo $_GET['num_fax']; ?>" /></td></tr>
						<tr><td>Email :</td><td><input type="text" name="email" value="<?php echo $_GET['email']; ?>" /></td>
						<td><input type="hidden" name="IdServ" value="<?php echo $_GET['IdServ']; ?>" /></td></tr>
						<tr><td colspan=2 align="center"><input type="submit" name="valider" value="Valider" />
						<input type="button" name="annuler" value="Annuler" onclick="location.href='./index.php?page=repertoire'" /></td></tr>
					</table>
				</form>
		<?php
			}
		?>
	</body>
</html>
Tout marche bien, sauf que quand j'édite un bonhomme, il n'y a plus de selected sur sa fonction.
Si par hasard quelqu'un saurait je lui en serait reconnaissant, mais ce n'est pas bien important.
Et je finirai bien par tomber dessus.
Merci de m'avoir soutenu, @+
Lenezir est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h30.


 
 
 
 
Partenaires

Hébergement Web