Bonjour,
Je vais essayer d'etre clair (ce n'est pas gagné) car ayant de niveau "bidouilleur" j'ai peur de ne pas appeler un chat un chat, je vous prie donc d'excuser par avance la pertinance de mon laguage.
Donc voila, j'avais besoin d'une interface d'administration de base de donnée, en récupérant des morceaux de script a droite et a gauche je me suis débrouillé à faire fonctionner une appli qui a priori tourne correctement.
Par contre je sollicite votre aide pour l'étape suivante car là c'est le blocage total, explication:
j'ai donc dans ma table 3 champs "id,produit,url" j'aimerai si c'est possible que l'affichage du champ "produit" soit sous la forme d'hyperlien dans mon tableau et que cet hyperlien soit la valeur du champ "url" de ma BDD ... est ce clair ??
voici mon "bricolage" de code
administration.php
et voila affichage.php
Code : 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 <?php $serveur='localhost'; $user='user'; $password='pass'; $base='test'; $champs=array( "articles"=>array("id","produit","url"), ); $connexion = mysql_connect("$serveur","$user","$password") or die ("Impossible de se connecter à la base de données"); mysql_select_db("$base",$connexion); function Ajouter($table, $query) { $insert=mysql_query("insert into $table set $query"); if ($insert==TRUE) { echo "Les données ont été correctement ajoutées<br />"; } else { echo "Erreur lors de l'ajout des données<br />"; } } function Modifier($table, $query, $where) { $update=mysql_query("update $table set $query where $where"); if ($update==TRUE) { echo "Les données ont été correctement modifiées<br />"; } else { echo "Erreur lors de la modification des données<br />"; } } function Supprimer($table, $where) { $delete=mysql_query("delete from $table where $where"); if ($delete==TRUE) { echo "Les données ont été correctement effacées<br />"; } else { echo "Erreur lors de la suppression des données<br />"; } } ?> <!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> <title>Administration des bdd</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="imagetoolbar" content="no" /> <meta content="TRUE" name="MSSmartTagsPreventParsing" /> <style type="text/css" media="screen"> @import url( css.css ); </style> <script language="Javascript"> function confirmation(url) { if(confirm('Voulez-vous vraiment supprimer ?')) document.location.href=url } </script> </head> <body> <!-- CADRE PRINCIPAL //--> <div id="cadreprincipal"> <!-- MENU //--> <div id="menu"> <div class="titremenu"> Articles </div> <div class="liensmenu"> <ul> <li><a href="<?=$_SERVER["PHP_SELF"]?>?table=articles">Gérer les articles</a></li> <li><a href="<?=$_SERVER["PHP_SELF"]?>?table=articles&q=Ajouter">Ajouter un article</a></li> </ul> </div> <br /> </div> <div id="main"> <?php if (isset($_GET["q"])) { $q=$_GET["q"]; } elseif(isset($_POST["q"])) { $q=$_POST["q"]; } else { $q=""; } if (isset($_GET["sq"])) { $sq=$_GET["sq"]; } elseif(isset($_POST["sq"])) { $sq=$_POST["sq"]; } else { $sq=""; } if (!isset($_GET["table"])) { echo "<div class=\"erreur\">Erreur ! La page n'a pas été appelée avec les bons paramètres.</div>"; } else { $table=$_GET["table"]; $prefixe=""; $table_utilisee="$prefixe".$table.""; switch($q) { case "Ajouter"; $nb_champs=sizeof($champs["$table"]); echo "<div class=\"titrecorps\">Ajout d'une entrée dans la table \"$table\"</div>"; if ($sq=="Valider") { $valeurs=""; $i=0; while($i<$nb_champs) { $nom_champ=$champs["$table"]["$i"]; if ($i!=0) { $valeurs.=" ,"; } $valeurs.="$nom_champ=\"$_POST[$nom_champ]\""; $i++; } Ajouter("$table_utilisee",$valeurs); ?> <script language="Javascript"> window.location="<? echo "".$_SERVER["PHP_SELF"]."?table=$table&msg=1"; ?>"; </script> <?php } else { echo " <form action=\"".$_SERVER["PHP_SELF"]."?table=$table&q=Ajouter&sq=Valider\" method=\"post\"> <table border=\"0\">"; $i=0; while($i<$nb_champs) { $nom_champ=$champs["$table"]["$i"]; $nom_champ_maj=strtoupper($nom_champ); echo " <tr> <td><b>$nom_champ_maj</b></td><td><textarea name=\"$nom_champ\" cols=\"40\" rows=\"3\"></textarea></td> </tr>"; $i++; } echo " <tr valign=\"top\"> <td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Valider\"></td> </tr> </table> </form>"; } break; case "Modifier"; $nb_champs=sizeof($champs["$table"]); echo "<div class=\"titrecorps\">Modification d'une entrée de la table \"$table\"</div>"; $id=$_GET["id"]; if ($sq=="Valider") { $valeurs=""; $i=0; while($i<$nb_champs) { $nom_champ=$champs["$table"]["$i"]; if ($i!=0) { $valeurs.=" ,"; } $valeurs.="$nom_champ=\"$_POST[$nom_champ]\""; $i++; } Modifier("$table_utilisee",$valeurs,"id=\"$id\""); ?> <script language="Javascript"> window.location="<? echo "".$_SERVER["PHP_SELF"]."?table=$table&msg=2"; ?>"; </script> <?php } else { $select=mysql_query("select * from $table_utilisee where id=\"$id\""); $res=mysql_fetch_array($select); echo " <form action=\"".$_SERVER["PHP_SELF"]."?table=$table&q=Modifier&sq=Valider&id=$id\" method=\"post\"> <table border=\"0\">"; $i=0; while($i<$nb_champs) { $nom_champ=$champs["$table"]["$i"]; $nom_champ_maj=strtoupper($nom_champ); echo " <tr> <td>$nom_champ_maj</td><td><textarea name=\"$nom_champ\" cols=\"40\" rows=\"3\">".$res["$nom_champ"]."</textarea></td> </tr>"; $i++; } echo " <tr valign=\"top\"> <td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Valider\"></td> </tr> </table> </form>"; } break; case "Supprimer"; echo "<div class=\"titrecorps\">Suppression d'une entrée de la table \"$table\"</div>"; Supprimer("$table_utilisee","id=\"$_GET[id]\""); ?> <script language="Javascript"> window.location="<? echo "".$_SERVER["PHP_SELF"]."?table=$table&msg=3"; ?>"; </script> <?php break; default: echo "<div class=\"titrecorps\">Enregistrements de la table \"$table\" :</div>"; $ordre=$champs["$table"]["0"]; $select=mysql_query("select * from $table_utilisee order by $ordre ASC"); $nb_enregistrements=mysql_num_rows($select); $tab_msg=array( "1"=>"Les données ont été correctement ajoutées !", "2"=>"Les données ont été correctement modifiées !", "3"=>"Suppression de l'enregistrement effectué !"); ?> » <?=$nb_enregistrements?> enregistrement(s) dans cette liste. <?php if (isset($_GET["msg"])) { echo "<div class=\"erreur\">".$tab_msg[$_GET["msg"]]."</div>"; } ?> <table border="1"> <tr align="center"><td><b>ACTIONS</b></td> <?php $nb_champs=sizeof($champs["$table"]); while(list($k,$nom_champ)=each($champs["$table"])) { $nom_champ_maj=strtoupper($nom_champ); echo "<td><b>$nom_champ_maj</b></td>"; } ?> </tr> <?php while ($res=mysql_fetch_array($select)) { echo "<tr><td>[<a href=\"".$_SERVER["PHP_SELF"]."?table=$table&q=Modifier&id=".$res["id"]."\">M</a>] - [<a href=\"javascript:confirmation('".$_SERVER["PHP_SELF"]."?table=$table&q=Supprimer&id=".$res["id"]."');\">S</a>]</td>"; $i=0; while($i<$nb_champs) { $nom_champ=$champs["$table"]["$i"]; if ($nom_champ=="mdp") { echo "<td>********</td>"; } else { echo "<td>".$res["$nom_champ"]."</td>"; } $i++; } echo "</tr>"; } ?> </table> <?php break; } } mysql_close(); ?> </div> </div> </body> </html>
Je vous assure que ce n'est pas faute d'avoir cherché, mais je n'ai hélas rien trouvé qui puisse m’orienter vers le résultat escompté, d'avance merci pour vos réponses et votre indulgence.
Code : 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 <?php $cnx = mysql_connect( "localhost", "user", "pass" ); $db= mysql_select_db( "mabase" ); $sql = "SELECT * FROM matable"; $requete = mysql_query( $sql, $cnx ) or die( "ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" ); echo "<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">\n" ; echo "<tr> <td><div align=\"center\">produit</div></td> </tr>" ; while( $result = mysql_fetch_assoc( $requete ) ) { echo "<tr>\n" ; echo "<td><div align=\"center\"><a href='".$result["url"]."'>".$result["produit"]."</a></div></td>\n"; echo "</tr>\n" ; } echo "</table>\n" ; $d = mysql_fetch_assoc($result); ?> <style type="text/css" media="screen"> @import url( css.css ); </style>
PS et si ca peu rendre service a qq'un je mets ke fichier CSS qui va bien
css.css
Code : 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 body { padding: 0px 0px 0px 0px; font-family: "trebuchet ms", verdana, arial, helvetica, sans-serif; font-size: 13px; color: #000000; } table { border:0px solid black; margin:0; padding:0; } td { border:1px dashed #999; margin:0; padding:10px; } a {text-decoration: none;} a:link, a:visited {color:#333996;} a:hover {color:#333996; background-color:#cacaca;} #cadreprincipal { width: auto; margin-top: 0px; margin-left: auto; margin-right: auto; background-color: white; } #main { float: left; width: 540px; margin: 0px 0px 0px 10px; padding-left: 15px; border-left: 1px dashed black; } .titrecorps { padding: 0px 0px 0px 0px; font-family: "Century Gothic", "Trebuchet MS", "Bitstream Vera Sans", verdana, lucida, arial, helvetica, sans-serif; font-size: 18px; color: #ff6600; letter-spacing: 1px; } #menu { float:left; width: 175px; margin:0px; padding: 0px 0px 0px 10px; border: 0px dashed #999; background-color:white; overflow: hidden; } .titremenu { padding: 0px 0px 0px 0px; font-family: "trebuchet ms", verdana, arial, helvetica, sans-serif; font-size: 14px; font-weight: 800; color: #999; text-align:left; text-indent:10px; letter-spacing:0.2em; } .titremenu:first-letter { font-size:20px; } .titremenu a { text-decoration: none; color: #999; } .titremenu a:first-letter { font-size:20px; } .liensmenu{ margin-bottom:1em; } .liensmenu ul{ width:100%; border-width:1px 0px 0px 0px; border-style:solid; border-color:#d6e1ec; padding:0; margin:0; } .liensmenu li{ border-bottom:1px solid #d6e1ec; list-style:none; margin:0; padding:0; } .liensmenu a { display:block; text-decoration:none; color:#369; background-color:#fff; padding-left:0.5em; padding-right:0.5em; font-family: "trebuchet ms", verdana, arial, helvetica, sans-serif; font-size:11px; } .liensmenu a:hover { background-color:#eff4fa; color:navy; } input,select { font-family: verdana, arial, helvetica, sans-serif; font-size: 11px; border: 1px dotted black; padding: 2px 2px 2px 2px; } .erreur { padding: 0px 0px 0px 0px; font-family: "trebuchet ms", verdana, arial, helvetica, sans-serif; font-size: 13px; color: red; background-color:#eee; } form { padding:0; margin:0; }
Partager