Utiliser Mysql avec php dans un tableau html
xunil2003
Messages postés
830
Statut
Membre
-
xunil2003 Messages postés 830 Statut Membre -
xunil2003 Messages postés 830 Statut Membre -
Bonjour,
je voudrai afficher ce qui a dans la ma table dans chaque colonne de mon tableau Html de ma page PHP, mais rien ne fonctionne je ne comprend pas comment faire, j'arrive uniquement a y faire fonctionné que sur 1 colonne, je n'arrive pas a trouver mon erreur
Pour cela j'ai créer la BDD 'domotique' et la table 'modules_x10''
Shematiquement voila ma table :
ID**nom_module**code_maison_unité**nom_commande_On**nom_commande_Off**nom_variateur_+**nom_variateur_-**
1**lumiere salon*A1**Allumer**Eteindre**+**-***
2**Lumiere couloir**B12**Allumer**Eteindre**+**-**
3**Lave vaiselle**C15**Marche**Arrêt**Inutilisable**Inutilisable**
3**Cumulus**C16**Marche**Arrêt**Inutilisable**Inutilisable**
esce que quelqu'un peut m'aider.
Merci d'avance, salutations.
-----------------------code----------------------------
<?php
mysql_connect("localhost", "root", ""); // Connexion à MySQL
mysql_select_db("domotique"); // Sélection de la base de donnée
//A partir d'ici table : modules_x10
$reponse1 = mysql_query("SELECT nom_module FROM modules_x10");
//$reponse2 = mysql_query("SELECT code_maison_unité FROM modules_x10");
//$reponse3 = mysql_query("SELECT nom_commande_On unité FROM modules_x10");
//$reponse4 = mysql_query("SELECT nom_commande_Off unité FROM modules_x10");
//$reponse5 = mysql_query("SELECT nom_variateur_+ unité FROM modules_x10");
//$reponse6 = mysql_query("SELECT nom_variateur_- unité FROM modules_x10");
?>
<table width="1672" border="1">
<tr>
<th width="404" scope="col">nom</th>
<th width="50" scope="col">C.M.U </th>
<th width="305" scope="col">On</th>
<th width="306" scope="col">Off</th>
<th width="285" scope="col">+</th>
<th width="282" scope="col">-</th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
while($result1=mysql_fetch_assoc($reponse1)) // tan qu'il y a des modules
//while($result2=mysql_fetch_assoc($reponse2)) // tan qu'il y a des modules
//while($result3=mysql_fetch_assoc($reponse3)) // tan qu'il y a des modules
//while($result4=mysql_fetch_assoc($reponse4)) // tan qu'il y a des modules
//while($result5=mysql_fetch_assoc($reponse5)) // tan qu'il y a des modules
//while($result6=mysql_fetch_assoc($reponse6)) // tan qu'il y a des modules
{
?>
<tr>
<th scope="row"><?php echo $result1["nom_module"]; ?></th>
<td><?php echo $result2["code_maison_unité"]; ?></td>
<td><form method="post"
action="" name="A1-On"><input name="A1-On" value="<?php //echo $result3["nom_commande_On"]; ?>" type="submit"></form></td>
<td><form method="post"
action="" name="A1-Off"><input name="A1-Off" value="<?php //echo $result4["nom_commande_Off"]; ?>" type="submit"></form></td>
<td><form method="post"
action="" name="A1-variateur+">
<input name="A1-variateur+" value="<?php //echo $result5["nom_variateur_+"]; ?>" type="submit" />
</form></td>
<td><form method="post"
action="" name="A1-variateur-">
<input name="A1-variateur-" value="<?php //echo $result6["nom_variateur_-"]; ?>" type="submit" />
</form></td>
</tr>
<?php
} //toute ta ligne est comprise dans la boucle while
?>
</table>
<p align="center">
<td><FORM>
<INPUT TYPE="button"
VALUE="Retour"
onClick="history.back()">
</FORM>
</body>
</html>
<?php
mysql_close(); // Fermeture de la connexion Mysql
?>
-------------fin du code-----------------------
je voudrai afficher ce qui a dans la ma table dans chaque colonne de mon tableau Html de ma page PHP, mais rien ne fonctionne je ne comprend pas comment faire, j'arrive uniquement a y faire fonctionné que sur 1 colonne, je n'arrive pas a trouver mon erreur
Pour cela j'ai créer la BDD 'domotique' et la table 'modules_x10''
Shematiquement voila ma table :
ID**nom_module**code_maison_unité**nom_commande_On**nom_commande_Off**nom_variateur_+**nom_variateur_-**
1**lumiere salon*A1**Allumer**Eteindre**+**-***
2**Lumiere couloir**B12**Allumer**Eteindre**+**-**
3**Lave vaiselle**C15**Marche**Arrêt**Inutilisable**Inutilisable**
3**Cumulus**C16**Marche**Arrêt**Inutilisable**Inutilisable**
esce que quelqu'un peut m'aider.
Merci d'avance, salutations.
-----------------------code----------------------------
<?php
mysql_connect("localhost", "root", ""); // Connexion à MySQL
mysql_select_db("domotique"); // Sélection de la base de donnée
//A partir d'ici table : modules_x10
$reponse1 = mysql_query("SELECT nom_module FROM modules_x10");
//$reponse2 = mysql_query("SELECT code_maison_unité FROM modules_x10");
//$reponse3 = mysql_query("SELECT nom_commande_On unité FROM modules_x10");
//$reponse4 = mysql_query("SELECT nom_commande_Off unité FROM modules_x10");
//$reponse5 = mysql_query("SELECT nom_variateur_+ unité FROM modules_x10");
//$reponse6 = mysql_query("SELECT nom_variateur_- unité FROM modules_x10");
?>
<table width="1672" border="1">
<tr>
<th width="404" scope="col">nom</th>
<th width="50" scope="col">C.M.U </th>
<th width="305" scope="col">On</th>
<th width="306" scope="col">Off</th>
<th width="285" scope="col">+</th>
<th width="282" scope="col">-</th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
while($result1=mysql_fetch_assoc($reponse1)) // tan qu'il y a des modules
//while($result2=mysql_fetch_assoc($reponse2)) // tan qu'il y a des modules
//while($result3=mysql_fetch_assoc($reponse3)) // tan qu'il y a des modules
//while($result4=mysql_fetch_assoc($reponse4)) // tan qu'il y a des modules
//while($result5=mysql_fetch_assoc($reponse5)) // tan qu'il y a des modules
//while($result6=mysql_fetch_assoc($reponse6)) // tan qu'il y a des modules
{
?>
<tr>
<th scope="row"><?php echo $result1["nom_module"]; ?></th>
<td><?php echo $result2["code_maison_unité"]; ?></td>
<td><form method="post"
action="" name="A1-On"><input name="A1-On" value="<?php //echo $result3["nom_commande_On"]; ?>" type="submit"></form></td>
<td><form method="post"
action="" name="A1-Off"><input name="A1-Off" value="<?php //echo $result4["nom_commande_Off"]; ?>" type="submit"></form></td>
<td><form method="post"
action="" name="A1-variateur+">
<input name="A1-variateur+" value="<?php //echo $result5["nom_variateur_+"]; ?>" type="submit" />
</form></td>
<td><form method="post"
action="" name="A1-variateur-">
<input name="A1-variateur-" value="<?php //echo $result6["nom_variateur_-"]; ?>" type="submit" />
</form></td>
</tr>
<?php
} //toute ta ligne est comprise dans la boucle while
?>
</table>
<p align="center">
<td><FORM>
<INPUT TYPE="button"
VALUE="Retour"
onClick="history.back()">
</FORM>
</body>
</html>
<?php
mysql_close(); // Fermeture de la connexion Mysql
?>
-------------fin du code-----------------------
A voir également:
- Utiliser Mysql avec php dans un tableau html
- Tableau word - Guide
- Trier un tableau excel - Guide
- Tableau ascii - Guide
- Comment utiliser chromecast sur tv - Guide
- Imprimer un tableau excel - Guide
2 réponses
pour afficher une variables php dans du code html, il faut tout d'abord que ta page soit en .php et puis tout simplement a la place de metre une balise <p> ou <a> tu tape <?php echo $variable; ?>
Rebonjour,
j'ai du mal m'exprimer, voila le code je j'ai réusi a faire fonctionner sur une colonne, evidament toute met page on l'extention PHP sinon elle ne pourai pas fonctionner sur wampserveur.
Le tout premier code que j'ai mis (ci haut desus), je les modifier pour afficher le resultat dans chaque colone de ma table Mysql, dans chaque colone de mon tableau html, mais je n'y arrive pas.
Merci, coordialement.
------------------------------------code--------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<?php
mysql_connect("localhost", "root", ""); // Connexion à MySQL
mysql_select_db("domotique"); // Sélection de la base de donnée
$reponse = mysql_query("SELECT nom_module FROM modules_x10");
?>
<table width="335" border="1">
<tr>
<th width="80" scope="col">nom</th>
<th width="50" scope="col">C.M.U </th>
<th width="50" scope="col">On</th>
<th width="30" scope="col">OFF</th>
<th width="36" scope="col">+</th>
<th width="49" scope="col">-</th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
while($result=mysql_fetch_assoc($reponse)) // tan qu'il y a des modules
{
?>
<tr>
<th scope="row"><?php echo $result["nom_module"]; ?></th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
} //toute la ligne est comprise dans la boucle while
?>
</table>
</body>
</html>
<?php
mysql_close(); // Fermeture de la connexion Mysql
?>
-----------------------------------------Fin du code---------------------------
j'ai du mal m'exprimer, voila le code je j'ai réusi a faire fonctionner sur une colonne, evidament toute met page on l'extention PHP sinon elle ne pourai pas fonctionner sur wampserveur.
Le tout premier code que j'ai mis (ci haut desus), je les modifier pour afficher le resultat dans chaque colone de ma table Mysql, dans chaque colone de mon tableau html, mais je n'y arrive pas.
Merci, coordialement.
------------------------------------code--------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<?php
mysql_connect("localhost", "root", ""); // Connexion à MySQL
mysql_select_db("domotique"); // Sélection de la base de donnée
$reponse = mysql_query("SELECT nom_module FROM modules_x10");
?>
<table width="335" border="1">
<tr>
<th width="80" scope="col">nom</th>
<th width="50" scope="col">C.M.U </th>
<th width="50" scope="col">On</th>
<th width="30" scope="col">OFF</th>
<th width="36" scope="col">+</th>
<th width="49" scope="col">-</th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
while($result=mysql_fetch_assoc($reponse)) // tan qu'il y a des modules
{
?>
<tr>
<th scope="row"><?php echo $result["nom_module"]; ?></th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
} //toute la ligne est comprise dans la boucle while
?>
</table>
</body>
</html>
<?php
mysql_close(); // Fermeture de la connexion Mysql
?>
-----------------------------------------Fin du code---------------------------