J'ai un gros soucis.
En effet je travail actuellement sur la partie administration de mon forum, mais il y a un hic.
Au niveau des droits des forum.
J'aimerais afficher le libellé des rangs (fait) dans un tableau qui contient des input type radio.
J'aimerais que en fonction des valeurs définis dans la BdD on puis cheched les radio.
Voici pour l'heure ce que j'ai fait
Le code (la page edit forum, qui contient l'édition des forums, donc des droits)
<?php
if (isset($_GET['forum_id']))
{
$query=$cnx->prepare('SELECT forum_id, cat_id, forum_name, forum_description
FROM t_forum
WHERE forum_id = :forum_id');
$query->bindValue(':forum_id',(int) $_GET['forum_id'],PDO::PARAM_INT);
$query->execute();
$data = $query->fetch();
$rank=$cnx->prepare('SELECT rank_id, rank_libelle, forum_auth_view, forum_auth_post, forum_auth_topic, forum_auth_announce, forum_auth_moderation FROM t_rank, t_forum');
$rank->execute();
?>
<h3>Edition du forum :: <?php echo $data['forum_name']; ?></h3>
<div id="sous_content">
<form action="./index.php?r=forum&mode=valider&forum_id=<?php echo $data['forum_id']; ?>" method="post">
<dl><input type="hidden" name="forum_id" value="<?php echo $data['forum_id']; ?>"/>
<dd>Nom du forum:<br /><input type="text" name="name" value="<?php echo $data['forum_name']; ?>" id="name"/></dd>
<dd>Description du forum:<br /><textarea cols=40 rows=4 name="description" id="description"><?php echo $data['forum_description']; ?></textarea></dd>
<dd>Catégorie : <br />
<select name="cat_id">
<?php
$query = $cnx->query('SELECT cat_id, cat_name
FROM t_cat ORDER BY cat_order DESC');
while($data2 = $query->fetch())
{
if($data2['cat_id'] == $data['cat_id'])
{
echo'<option value="'.$data2['cat_id'].'"
selected="selected">'.stripslashes(htmlspecialchars($data2['cat_name'])).'
</option>';
}
else
{
echo'<option value="'.$data2['cat_id'].'">'.$data2['cat_name'].'</option>';
}
}
?>
</select></dd>
</dl>
<dl>
<dd>
<fieldset style="border:none;">
<legend style="font-size:21px;font-weight:bold;">Permissions du forum</legend>
<p>L'id à rentrer pour les permissions des utilisateurs correspond à l'id des rangs.</p>
<p>Pour vous aider, référez vous au tableau de droite: Tableau des rangs.</p>
<p>Les rangs supérieurs au rang séldctionné héritent de ce dernidr.<br/>
Si un membre peux lire un message, les rangs suppérieurs le pourront aussi, mais pas ceux inférieurs.</p>
<table class="autorisation" cellpadding="3">
<tr class="headautorisation">
<th class="actions">Actions</th>
<?php
while ($data1 = $rank->fetch())
{
$forum_auth_view = $data1['forum_auth_view'];
$forum_auth_post = $data1['forum_auth_post'];
$forum_auth_topic = $data1['forum_auth_topic'];
$forum_auth_announce = $data1['forum_auth_announce'];
$forum_auth_moderation = $data1['forum_auth_moderation'];
echo $data1['rank_id'].' '.$data1['rank_libelle'];
echo '<th class="autorisation">'.$data1['rank_libelle'].'</th>';
}
$table_auth=array('Peut lire les messages','Peut répondre aux messages','Peut poster un sujet','Peut publier une annonce','Peut modérer le forum');
?>
</tr>
<?php
$i=1;
foreach ($table_auth as $value)
{
$nexi = $i++;
echo '<tr class="autorisation">
<th class="autorisation">'.$value.'</th>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
<td class="autorisation"><input type="radio" value="" name="auth_'.$nexi.'[]"/></td>
</tr>';
}
?>
</table>
</fieldset>
</dd>
</dl>
<dl>
<dd><input type="submit" name="envoie" value="Envoyer"/></dd>
</dl>
</form>
</div>
<?php
$query->CloseCursor();
}
?>
la structure des tablesLa table t_ranks et ses donées.
--
-- Structure de la table `t_rank`
--
CREATE TABLE IF NOT EXISTS `t_rank` (
`rank_id` int(10) NOT NULL AUTO_INCREMENT,
`rank_libelle` varchar(64) NOT NULL,
PRIMARY KEY (`rank_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Contenu de la table `t_rank`
--
INSERT INTO `t_rank` (`rank_id`, `rank_libelle`) VALUES
(1, 'Bannis'),
(2, 'Visiteur'),
(3, 'Membre'),
(4, 'Moderateur'),
(5, 'Admin'),
(6, 'Operateur');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
La table t_forum et ses données.
--
-- Structure de la table `t_forum`
--
CREATE TABLE IF NOT EXISTS `t_forum` (
`forum_id` int(11) NOT NULL AUTO_INCREMENT,
`cat_id` int(11) NOT NULL,
`forum_name` varchar(45) NOT NULL,
`forum_description` varchar(45) CHARACTER SET latin1 COLLATE latin1_german2_ci NOT NULL,
`forum_order` int(11) NOT NULL,
`forum_auth_view` tinyint(8) unsigned NOT NULL,
`forum_auth_post` tinyint(8) unsigned NOT NULL,
`forum_auth_topic` tinyint(8) unsigned NOT NULL,
`forum_auth_announce` tinyint(8) unsigned NOT NULL,
`forum_auth_moderation` tinyint(8) unsigned NOT NULL,
`forum_last_post` int(11) NOT NULL,
PRIMARY KEY (`forum_id`),
KEY `t_forum_FKIndex1` (`cat_id`),
KEY `fk_t_cat1` (`cat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Contenu de la table `t_forum`
--
INSERT INTO `t_forum` (`forum_id`, `cat_id`, `forum_name`, `forum_description`, `forum_order`, `forum_auth_view`, `forum_auth_post`, `forum_auth_topic`, `forum_auth_announce`, `forum_auth_moderation`, `forum_last_post`) VALUES
(1, 1, 'Mon premier forum', 'Voici un forum de test', 1, 2, 3, 3, 4, 4, 1);
--
-- Contraintes pour les tables exportées
--
--
-- Contraintes pour la table `t_forum`
--
ALTER TABLE `t_forum`
ADD CONSTRAINT `fk_t_cat1` FOREIGN KEY (`cat_id`) REFERENCES `t_cat` (`cat_id`);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Un aperçu de ce que ça donne actuellement
Merci de votre aide, je coince, j'avoue, j'en avais déjà fait pourtant, mais pas dynamiquement.
Cordialement
