Probleme liste deroulante lie bdd

metalic rider -  
 metalic rider -
Bonjour tous le monde, j'ai un petit probleme, en fait j'ai une liste deroulante php qui affiche la table 'commercial' de ma bdd en ramenant leur nom, et leur prenom. jusqu'ici tout va bien. Ensuite j'ai une requete qui associe l'id commercial a l'id client, grace a cela, j'esperais en selectionnant un commercial de ma liste deroulante, afficher dans deux champ a part, le nom et le prenom du client qui lui est associe mais mon champ ne me rammene que l'id numero 1 de ma table client, soit le nom et le prenom, et peut importe la selection de ma liste deroulante l'id 1 revient. Quelqu'un pourrait t'il m'aider please?
Voici le script:

<?php

if (isset($_POST["com"]) )
$id_com=$_POST["com"];
else
$id_com=1;

print("<form action='profil.php' method='POST' id='form_select'>");
print("<select name ='com' onchange ='javascript:document.form_select.submit()'>");

$sql=sprintf("SELECT * FROM commercial");
$mysql=mysql_query($sql);

$sql2=sprintf("SELECT * FROM commercial, client where commercial.idcommercial=client.idclient AND commercial.idcommercial=%s",$id_com);
$mysql2=mysql_query($sql2);


$fiche=mysql_fetch_array($mysql2);

while ($val =mysql_fetch_array($mysql))
{

$str = "";
if($val["idcommercial"]==$id_com)
{
$str = " selected = 'selected'";
}
print("<option value='".$val['idcommercial']." ".$str.">".$val["nom"] ." ". $val["prenom"]."</option>");

}
print("</select>");
print("</form>");
?>

<html>
<body>
Nom client: <input type="text" name="affnomc" value="<?php echo($fiche["nomc"])?>"></input>
</br>
Prenom client: <input type="text" name="affnomc" value="<?php echo($fiche["prenomc"])?>"></input>
</body>
</html>
A voir également:

1 réponse

metalic rider
 
Bonjour tous le monde, j'ai un petit probleme, en fait j'ai une liste deroulante php qui affiche la table 'commercial' de ma bdd en ramenant leur nom, et leur prenom. jusqu'ici tout va bien. Ensuite j'ai une requete qui associe l'id commercial a l'id client, grace a cela, j'esperais en selectionnant un commercial de ma liste deroulante, afficher dans deux champ a part, le nom et le prenom du client qui lui est associe mais mon champ ne me rammene que l'id numero 1 de ma table client, soit le nom et le prenom, et peut importe la selection de ma liste deroulante l'id 1 revient. Quelqu'un pourrait t'il m'aider please?
Voici le script:

<?php

if (isset($_POST["com"]) )
$id_com=$_POST["com"];
else
$id_com=1;

print("<form action='profil.php' method='POST' id='form_select'>");
print("<select name ='com' onchange ='javascript:document.form_select.submit()'>");

$sql=sprintf("SELECT * FROM commercial");
$mysql=mysql_query($sql);

$sql2=sprintf("SELECT * FROM commercial, client where commercial.idcommercial=client.idclient AND commercial.idcommercial=%s",$id_com);
$mysql2=mysql_query($sql2);


$fiche=mysql_fetch_array($mysql2);

while ($val =mysql_fetch_array($mysql))
{

$str = "";
if($val["idcommercial"]==$id_com)
{
$str = " selected = 'selected'";
}
print("<option value='".$val['idcommercial']." ".$str.">".$val["nom"] ." ". $val["prenom"]."</option>");

}
print("</select>");
print("</form>");
?>

<html>
<body>
Nom client: <input type="text" name="affnomc" value="<?php echo($fiche["nomc"])?>"></input>
</br>
Prenom client: <input type="text" name="affnomc" value="<?php echo($fiche["prenomc"])?>"></input>
</body>
</html>
0