Bonjour,
J'ai un soucis d'optimisation et de modification, à l'initial le code ressemblai à ça:
En fait le script est un forum et cette portion de code permet l'affichage:
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 <?php $queryf = sql_query("SELECT name, moderator, fid FROM $table_forums WHERE type='forum'"); while ($mod = sql_fetch_object($queryf)) { ?> <tr class="tablerow altbg2"> <td><?php echo $mod->name ?></td> <td><input type="text" size="60" name="mod<?php echo $mod->fid ?>" value="<?php echo htmlspecialchars($mod->moderator) ?>" /></td> </tr> <?php $querys = sql_query("SELECT name, moderator, fid FROM $table_forums WHERE type='sub' AND fup='" . intval($mod->fid) . "' ORDER BY displayorder"); while ($mod = sql_fetch_object($querys)) { ?> <tr class="tablerow altbg2"> <td align="right"> <?php echo $mod->name ?></td> <td align="right"> <input type="text" size="55" name="mod<?php echo $mod->fid ?>" value="<?php echo htmlspecialchars($mod->moderator) ?>" /></td> </tr> <?php } } ?>
-De nom du forum et ses modérateurs
-Des noms des sous-forums (du forum 'fid') et ses modérateurs
ex:
- Forum1 (modérateur:toto, titi, tata)
- -Sous-forum1 (modérateur:toto, titi, tata)
- -Sous-forum2 (modérateur:toto)
- Forum2 (modérateur:tata)
- -Sous-forum1 (modérateur:toto, titi, tata)
- -etc
Les deux requêtes se font sur la même table $table_forums
De mon coté, je souhaite optimiser tout ça par une séparation php/html via un moteur de template et optimisation de cette boucle.
J'ai donc fait ça:
Et pour la sortie template
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 $mod1 = array(); $modforumlist = array(); $mod2 = array(); $modsubforumlist = array(); $queryf = sql_query("SELECT name, moderator, fid FROM $table_forums WHERE type='forum'"); while ($mod1 = sql_fetch_assoc($queryf)) { $modforumlist[] = $mod1; $querys = sql_query("SELECT name, moderator, fid FROM $table_forums WHERE type='sub' AND fup='" . intval($mod1['fid']) . "' ORDER BY displayorder"); while ($mod2 = sql_fetch_assoc($querys)) { $modsubforumlist[] = $mod2; } } /* Template initialisieren */ $template = load_class('Template'); $template->init_path(__FILE__); $template->modforumlist = $modforumlist; $template->modsubforumlist = $modsubforumlist; $template->display('admin.mods.html');
Mais ça m'a pas lair très propre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php foreach ($this->modforumlist as $mod1) : ?> <tr> <td><?php echo $mod1['name'] ?></td> <td><input type="text" size="60" name="mod<?php echo $mod1['fid'] ?>" value="<?php echo htmlspecialchars($mod1['moderator']) ?>" /></td> </tr> <?php foreach ($this->modsubforumlist as $mod2) : ?> <tr class="tablerow altbg2"> <td align="right"> <?php echo $mod2['name'] ?></td> <td align="right"> <input type="text" size="55" name="mod<?php echo $mod2['fid'] ?>" value="<?php echo htmlspecialchars($mod2['moderator']) ?>" /></td> </tr> <?php endforeach ?> <?php endforeach ?>, ainsi si quelqu'un a une ou des idées merci d'avance
![]()
Partager