Probleme affichage d'un tableau php
Résolu
wsara5454
Messages postés
57
Date d'inscription
Statut
Membre
Dernière intervention
-
wsara5454 Messages postés 57 Date d'inscription Statut Membre Dernière intervention -
wsara5454 Messages postés 57 Date d'inscription Statut Membre Dernière intervention -
Bonsoir,
j'ai un petit problème,
je veux lorsque je selectoinne une valeur de la liste deroulante et je click sur un bouton un tableau s'affiche avec les resultats d'une requete sql voici mon code je ne sais pas ou est l'erreur . merci bcp
j'ai un petit problème,
je veux lorsque je selectoinne une valeur de la liste deroulante et je click sur un bouton un tableau s'affiche avec les resultats d'une requete sql voici mon code je ne sais pas ou est l'erreur . merci bcp
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Base de Données</title> </head> <body> <?php $hostname="localhost"; $user="root"; $password=""; $base="etudiant"; $id=mysql_connect($hostname,$user,$password); mysql_select_db($base,$id); $sql="select * from inscription"; $res=mysql_query($sql); $sqlville="select distinct ville from inscription"; $resville=mysql_query($sqlville); /* while ($tab = mysql_fetch_row($res)){ echo " matricule : $tab[0] "; echo " prenom : $tab[1] "; echo " nom : $tab[2] "; echo " ville : $tab[3] "; echo " date de naissance: $tab[4] </br> "; ** */ echo( "<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">\n" ); echo( "<tr> <td><div align='center'>Matricule</div></td> <td><div align='center'>Prenom</div></td> <td><div align='center'>Nom</div></td> <td><div align='center'>Ville</div></td> <td><div align='center'>Date de naissance</div></td> </tr>" ); while( $tab = mysql_fetch_array( $res ) ) { echo "<tr>\n "; echo "<td><div align='center'>".$tab[0]."</div></td>\n" ; echo "<td><div align='center'>".$tab[1]."</div></td>\n" ; echo "<td><div align='center'>".$tab[2]."</div></td>\n" ; echo "<td><div align='center'>".$tab[3]."</div></td>\n" ; echo "<td><div align='center'>".$tab[4]."</div></td>\n" ; echo "</tr>\n" ; ** echo "</table><br>\n" ; echo "<center>"; echo "ville : "; echo "<select name='l'>"; echo "<option></option>"; while($row = mysql_fetch_array($resville)){ $ch=$row["ville"]; echo "<option value='".$ch."'>".$ch."</option>"; ** mysql_free_result($resville); echo "</select>"; echo "<input type='submit' value='rechercher' name='b'"; echo "</center>"; if(isset($_POST["l"])) { if (isset($_POST["b"])) { $sqlRech="select matricule,prenom,nom from inscription where ville='$ch'"; $resRech=mysql_query($sqlRech); while($resRech) { echo "<table border='1' align='center'\n" ; echo( "<tr> <td><div align='center'>Matricule</div></td> <td><div align='center'>Prenom</div></td> <td><div align='center'>Nom</div></td> </tr></table>" ); ** ** ** while($row=mysql_fetch_array($resRech)){ echo "<table><tr>\n "; echo "<td><div align='center'>".$row["matricule"]."</div></td>\n" ; echo "<td><div align='center'>".$row["prenom"]."</div></td>\n" ; echo "<td><div align='center'>".$row["nom"]."</div></td>\n" ; echo "</tr></table>\n"; ** ?> </body> </html>
A voir également:
- Probleme affichage d'un tableau php
- Tableau word - Guide
- Trier un tableau excel - Guide
- Tableau ascii - Guide
- Imprimer un tableau excel - Guide
- Tableau croisé dynamique - Guide
5 réponses
Salut,
Ok, mais quels sont les messages d'erreurs? Que fait ce code?
En regardant vite fait, je ne vois pas de formulaire du coup je ne vois pas bien à quoi correspond le bouton submit..
Ok, mais quels sont les messages d'erreurs? Que fait ce code?
En regardant vite fait, je ne vois pas de formulaire du coup je ne vois pas bien à quoi correspond le bouton submit..
il n y a pas des messages d'erreurs pendant l'exécution juste le deuxième tableau ne s'affiche pas alors je croix qu'il y a un erreur dans le code
j'ai ajouté la balise <form> et encore pas d'affichage
j'ai ajouté la balise <form> et encore pas d'affichage
salut,
voici mon nouveau code <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Base de Données</title>
</head>
<body>
<form name=f method="POST" >
<?php
$hostname="localhost";
$user="root";
$password="";
$base="etudiant";
$id=mysql_connect($hostname,$user,$password);
mysql_select_db($base,$id);
$sql="select * from inscription";
$res=mysql_query($sql);
$sqlville="select distinct ville from inscription";
$resville=mysql_query($sqlville);
/*
while ($tab = mysql_fetch_row($res)){
echo " matricule : $tab[0] ";
echo " prenom : $tab[1] ";
echo " nom : $tab[2] ";
echo " ville : $tab[3] ";
echo " date de naissance: $tab[4] </br> ";
}
*/
echo( "<table border='1' cellpadding='1' cellspacing='1' align='center'>\n" );
echo( "<tr>
<td><div align='center'>Matricule</div></td>
<td><div align='center'>Prenom</div></td>
<td><div align='center'>Nom</div></td>
<td><div align='center'>Ville</div></td>
<td><div align='center'>Date de naissance</div></td>
</tr>" );
while( $tab = mysql_fetch_array( $res ) )
{
echo "<tr>\n ";
echo "<td><div align='center'>".$tab[0]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[1]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[2]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[3]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[4]."</div></td>\n" ;
echo "</tr>\n" ;
}
echo "</table><br>\n" ;
echo "<center>";
echo "ville : ";
echo "<select name='l'>";
echo "<option></option>";
while($tab = mysql_fetch_array($resville)){
$ch=$tab["ville"];
echo "<option value='".$ch."'>".$ch."</option>";
}
mysql_free_result($resville);
echo "</select>";
echo "<input type='submit' value='rechercher' name='b'";
echo "</center>";
if(isset($_POST["l"]))
{
if (isset($_POST["b"]))
{
$sqlRech="select matricule,prenom,nom from inscription where ville='$ch';";
$resRech=mysql_query($sqlRech);
/*while($resRech)
{ */
echo "<table border='1' align='center'\n" ;
echo( "<tr>
<td><div align='center'>Matricule</div></td>
<td><div align='center'>Prenom</div></td>
<td><div align='center'>Nom</div></td>
</tr>" );
//}
while($tab=mysql_fetch_array($resRech)){
echo "<td><div align='center'>".$tab["matricule"]."</div></td>" ;
echo "<td><div align='center'>".$tab["prenom"]."</div></td>" ;
echo "<td><div align='center'>".$tab["nom"]."</div></td>" ;
echo "</tr></table>";
}
}
}
?>
</form>
</body>
</html>
voici mon nouveau code <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Base de Données</title>
</head>
<body>
<form name=f method="POST" >
<?php
$hostname="localhost";
$user="root";
$password="";
$base="etudiant";
$id=mysql_connect($hostname,$user,$password);
mysql_select_db($base,$id);
$sql="select * from inscription";
$res=mysql_query($sql);
$sqlville="select distinct ville from inscription";
$resville=mysql_query($sqlville);
/*
while ($tab = mysql_fetch_row($res)){
echo " matricule : $tab[0] ";
echo " prenom : $tab[1] ";
echo " nom : $tab[2] ";
echo " ville : $tab[3] ";
echo " date de naissance: $tab[4] </br> ";
}
*/
echo( "<table border='1' cellpadding='1' cellspacing='1' align='center'>\n" );
echo( "<tr>
<td><div align='center'>Matricule</div></td>
<td><div align='center'>Prenom</div></td>
<td><div align='center'>Nom</div></td>
<td><div align='center'>Ville</div></td>
<td><div align='center'>Date de naissance</div></td>
</tr>" );
while( $tab = mysql_fetch_array( $res ) )
{
echo "<tr>\n ";
echo "<td><div align='center'>".$tab[0]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[1]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[2]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[3]."</div></td>\n" ;
echo "<td><div align='center'>".$tab[4]."</div></td>\n" ;
echo "</tr>\n" ;
}
echo "</table><br>\n" ;
echo "<center>";
echo "ville : ";
echo "<select name='l'>";
echo "<option></option>";
while($tab = mysql_fetch_array($resville)){
$ch=$tab["ville"];
echo "<option value='".$ch."'>".$ch."</option>";
}
mysql_free_result($resville);
echo "</select>";
echo "<input type='submit' value='rechercher' name='b'";
echo "</center>";
if(isset($_POST["l"]))
{
if (isset($_POST["b"]))
{
$sqlRech="select matricule,prenom,nom from inscription where ville='$ch';";
$resRech=mysql_query($sqlRech);
/*while($resRech)
{ */
echo "<table border='1' align='center'\n" ;
echo( "<tr>
<td><div align='center'>Matricule</div></td>
<td><div align='center'>Prenom</div></td>
<td><div align='center'>Nom</div></td>
</tr>" );
//}
while($tab=mysql_fetch_array($resRech)){
echo "<td><div align='center'>".$tab["matricule"]."</div></td>" ;
echo "<td><div align='center'>".$tab["prenom"]."</div></td>" ;
echo "<td><div align='center'>".$tab["nom"]."</div></td>" ;
echo "</tr></table>";
}
}
}
?>
</form>
</body>
</html>
Il me semble que l'attribut action est obligatoire dans la balise form pour que ton formulaire soit valide, même si cet attribut est vide!
<form action="" name="f" method="POST" >
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question