Probleme champs d'une liste repetitifs
Bonjour
Voila j'ai creer un script pour modifier des clients dans une base de donnée !
On selectionne le Nom et apres sa affiche les differentes informations du client selectionné !
Voici le script qui selctionne le nom du client:
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
| <table width="22%" border="1">
<tr>
<td width="64%"><p><a href="index.php">Accueil</a></p>
<p><a href="CreationBase.php">Creer Base</a></p>
<p><a href="creationClient.php">Creer un client</a></p>
<p><a href="AffBase.php">Afficher Base</a></p>
<p><a href="AffBaseParVille.php">Afficher Base par ville</a></p>
<p><a href="modifierclient.php">Modifier un client</a></p>
</td>
<td width="36%">
<?php
// Configuration de la connexion à la base de données
define('MYSQL_HOTE', 'localhost');
define('MYSQL_UTILISATEUR', 'root');
define('MYSQL_MOT_DE_PASSE', '');
define('MYSQL_BASE_DE_DONNEES', 'AquaVendee');
$nom = isset($_POST['Nom']) ? $_POST['Nom'] : '';
$prenom = isset($_POST['Prenom']) ? $_POST['Prenom'] : '';
// ...
// Connexion à la base de donnée
mysql_connect(MYSQL_HOTE, MYSQL_UTILISATEUR, MYSQL_MOT_DE_PASSE) or die('<h1>Connexion au serveur impossible !</h1>');
mysql_select_db(MYSQL_BASE_DE_DONNEES) or die('<h1>Connexion impossible à la base</h1>');
echo '<form method="post" action="valider.php">';
// Affichage du langage choisi
if ($nom) {
$query = mysql_query("SELECT * FROM client WHERE Nom='$nom';") or die ( mysql_error() );
$array = mysql_fetch_array($query);
// echo 'Vous avez choisi le nom : ' . $array['Nom'];
}
// Début du script
$query = mysql_query("SELECT Nom FROM client;") or die (mysql_error());
if ($query)
{
echo '<form method="post">';
echo '<select name="Nom">';
while ($array = mysql_fetch_array($query))
{
if ($nom == $array["Nom"])
{
echo '<option value="' . $array['Nom'] . '" selected>' . $array['Nom'] . '</option>';
}
else
{
echo '<option value="'.$array['Nom'] . '">' . $array['Nom'] . '</option>';
}
}
echo '</select>';
echo '<input type="submit" value="OK">';
echo '</form>';
}
mysql_close();
?>
</td>
</tr>
</table> |
Voici le script qui affiche en fonction du nom du client:
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
| <?php
$nom=$_POST["Nom"];
$f = mysql_connect ("localhost", "root", "");
mysql_select_db ("AquaVendee");
// Recuperation des valeurs des différents champs
$req ="select Prenom from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$prenom = $arr['Prenom']; //prend la valeur de la clé Prenom
$req ="select Ville from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$ville = $arr['Ville']; //prend la valeur de la clé Prenom
$req ="select Adresse from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$adresse = $arr['Adresse']; //prend la valeur de la clé Prenom
$req ="select TypeApp from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$app = $arr['TypeApp']; //prend la valeur de la clé Prenom
$req ="select DateV from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$dv = $arr['DateV']; //prend la valeur de la clé Prenom
$req ="select DateMS from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$dms = $arr['DateMS']; //prend la valeur de la clé Prenom
$req ="select DateM from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$dm = $arr['DateM']; //prend la valeur de la clé Prenom
$req ="select Commentaire from client where Nom='$nom' ";
$ok=mysql_query($req,$f); //retouve les données brutes
$arr = mysql_fetch_array($ok); //prend la première ligne des résultats et transforme en tableau
$com = $arr['Commentaire']; //prend la valeur de la clé Prenom
mysql_close($f);
?>
<table width="50%" border="1">
<tr>
<td width="34%"><p><a href="index.php">Accueil</a></p>
<p><a href="CreationBase.php">Creer Base</a></p>
<p><a href="creationClient.php">Creer un client</a></p>
<p><a href="AffBase.php">Afficher Base</a></p>
<p><a href="AffBaseParVille.php">Afficher Base par ville</a></p>
<p><a href="modifierclient.php">modifier un client</a></p> </td>
<td width="66%"><form method="post" action="insertionClient2.php" name="form2">
<table width="94%" border="0">
<tr>
<td width="53%">Nom</td>
<td width="47%"> <input name="nom" type="text" id="nom" value="<?php echo"$nom"?>">
</td>
</tr>
<tr>
<td>Prenom</td>
<td> <input name="prenom" type="text" id="prenom" value="<?php echo "$prenom" ?>">
</td>
</tr>
<tr>
<td>Ville</td>
<td> <input name="ville" type="text" id="ville" value="<?php echo"$ville"?>">
</td>
</tr>
<tr>
<td>Adresse</td>
<td> <input name="adresse" type="text" id="adresse" value="<?php echo "$adresse" ?>">
</td>
</tr>
<tr>
<td>Type Appareil
<td> <input name="app" type="text" id="app" value="<?php echo "$app "?>">
</td>
</tr>
<tr>
<td>Date Vente</td>
<td> <input name="dv" type="text" id="dv" value="<?php echo "$dv" ?>">
</td>
</tr>
<tr>
<tr>
<td>Date mise en Service</td>
<td> <input name="dmes" type="text" id="dmes" value="<?php echo "$dms" ?>">
</td>
</tr>
<tr>
<td>Date maintenance</td>
<td> <input name="dm" type="text" id="dm" value="<?php echo "$dm"?>">
</td>
</tr>
<tr>
<td>Commentaire</td>
<td> <input name="com" type="text" id="com" value="<?php echo "$com"?>">
</td>
</tr>
</table>
<input name="submit" type="submit" value="OK">
</form></td>
</tr>
</table>
<p> </p> |
Mon probleme c'est que si il y a plusieurs fois le meme nom sa m'affiche plusieurs fois le nom dans la liste !
Je souhaiterai qu'il n'y ai qu'une fois le meme nom !
Par la suite j'essairai qu'en fonction du nom selectionner au debut tout les noms etant associer au nom saffiche dans une liste !
Merci de votre aide