Bonjour à Tous
Débutant en PHP, je bute depuis plusieurs jours sur ce problème
J'arrive bien à afficher mes données et créer un tableau, à survoler les lignes et à créer mes champs, mais je n'arrive pas à afficher les données d'une ligne dans les champs.
La partie OnClick ne fonctionne pas, et je n'arrive pas à identifier mon erreur
Puis-je avoir de l'aide de votre part
Bien à vous
Le code:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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 <!DOCTYPE html> <html> <head> <th>ARTICLE List</th><br><br> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Mise en couleur de fond --> <body bgcolor='#F0F8FF'> </body> <!-- Mise en couleur de la ligne au survol & affichage du pointer --> <style> table tr:not(:first-child){ cursor: pointer;transition: all .25s ease-in-out; } table tr:not(:first-child):hover{background-color: #ddd;} </style> </head> <body> <!-- Création des champs de saisis pour Update --> ID:<input type="text" name="id" id="id"><br> Ref:<input type="text" name="ref" id="ref"><br> Design:<input type="text" name="design" id="design"><br> Price:<input type="text" name="price" id="price"><br> Supplier:<input type="text" name="supplier" id="supplier"><br> <!-- Création de BTN --> <button onclick="addHtmlTableRow();">Add</button> <button onclick="editHtmlTbleSelectedRow();">Edit</button> <button onclick="removeSelectedRow();">Remove</button> <table id="TAB_ART" border="1"> <!-- Connexion & requête --> <?php $mysqli = new mysqli('localhost', 'root', 'root', 'simag_prod'); $mysqli->set_charset("utf8"); $requete = 'SELECT * FROM articles'; $resultat = $mysqli->query($requete); $strOut = '<table>'.chr(13); // Contour du tableau --> $strOut = '<table border="1" width="650">'.chr(13); while ($ligne = $resultat->fetch_assoc()) { //--Affichage des champs (champs de la table SQL) $strOut.= '<tr>'.chr(13); $strOut.= ' <td> '.$ligne['art_id'].'</td>'.chr(13); $strOut.= ' <td>'.$ligne['art_ref'].'</td>'.chr(13); $strOut.= ' <td> '.$ligne['art_design'].'</td>'.chr(13); $strOut.= ' <td> '.$ligne['art_prix'].'</td>'.chr(13); $strOut.= ' <td> '.$ligne['art_four'].'</td>'.chr(13); $strOut.= '</tr>'.chr(13); } //-- $strOut.='</table>'; echo $strOut; //-- $mysqli->close(); ?> </table> <!-- Affichage dans les champs construit --> <script> var table = document.getElementById('TAB_ART'); for(var i = 1; i < table.rows.length; i++) { table.rows[i].onclick = function() { //rIndex = this.rowIndex; document.getElementById("id").value = this.cells[0].innerHTML; document.getElementById("ref").value = this.cells[1].innerHTML; document.getElementById("design").value = this.cells[2].innerHTML; document.getElementById("price").value = this.cells[3].innerHTML; document.getElementById("Supplier").value = this.cells[4].innerHTML; }; } </script> </body> </html>
Partager