Bonjour,
J'ai suivi le tutoriel de création de badges et je me demandait comment on fais pour afficher les badges sur la page utilisateur concernée.
Merci,
Ok,
On obtient ca à la fin du tuto :
-- phpMyAdmin SQL Dump
-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Client: localhost
-- Généré le: Mar 31 Juillet 2012 à 08:35
-- Version du serveur: 5.5.24-log
-- Version de PHP: 5.4.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `tuto`
--
-- --------------------------------------------------------
--
-- Structure de la table `badges`
--
CREATE TABLE IF NOT EXISTS `badges` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
--
-- Contenu de la table `badges`
--
INSERT INTO `badges` (`id`, `name`) VALUES
(1, 'Poster 1 article'),
(2, 'Poster 3 articles'),
(3, 'Poster 2 commentaire');
-- --------------------------------------------------------
--
-- Structure de la table `badges_users`
--
CREATE TABLE IF NOT EXISTS `badges_users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`badge_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
--
-- Contenu de la table `badges_users`
--
INSERT INTO `badges_users` (`id`, `badge_id`, `user_id`) VALUES
(3, 1, 1),
(4, 2, 1),
(5, 3, 1);
-- --------------------------------------------------------
--
-- Structure de la table `comments`
--
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`username` varchar(60) NOT NULL,
`mail` varchar(255) NOT NULL,
`content` text NOT NULL,
`ref` varchar(60) DEFAULT 'tutoriel',
`ref_id` int(4) NOT NULL,
`ip` varchar(50) NOT NULL,
`created` datetime NOT NULL,
`parent_id` int(9) NOT NULL,
`user_id` int(9) DEFAULT NULL,
`spam` int(1) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `tutoriel_id` (`ref_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Contenu de la table `comments`
--
INSERT INTO `comments` (`id`, `username`, `mail`, `content`, `ref`, `ref_id`, `ip`, `created`, `parent_id`, `user_id`, `spam`) VALUES
(1, '', '', 'Ajouter mon commentaire', 'Post', 1, '127.0.0.1', '2012-07-30 09:33:21', 0, 1, 0),
(2, '', '', 'Mon second commentaire', 'Post', 1, '127.0.0.1', '2012-07-30 09:38:31', 0, 1, 0),
(3, 'aze', 'aze@aze.fr', 'aze', 'Post', 1, '127.0.0.1', '2012-07-30 09:39:43', 0, NULL, 0),
(4, 'Mon pseudo', 'monmail@mail.fr', 'Mon commentaire', 'Post', 1, '127.0.0.1', '2012-07-30 09:40:29', 0, NULL, 0);
-- --------------------------------------------------------
--
-- Structure de la table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`content` longtext NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
--
-- Contenu de la table `posts`
--
INSERT INTO `posts` (`id`, `name`, `content`, `user_id`) VALUES
(1, 'Fear of a Bot Planet', '\r\n<p>Please, Don-Bot… look into your hard drive, and open your mercy file! Dr. Zoidberg, that doesn''t make sense. But, okay! Look, everyone wants to be like Germany, but do we really have the pure strength of ''will''? Is that a cooking show? Oh dear! She''s stuck in an infinite loop, and he''s an idiot! Well, that''s love for you.</p>\r\n<h2>Fear of a Bot Planet</h2>\r\n<p>As an interesting side note, as a head without a body, I envy the dead. I''ll get my kit! Anyhoo, your net-suits will allow you to experience Fry''s worm infested bowels as if you were actually wriggling through them. I didn''t ask for a completely reasonable excuse! I asked you to get busy! What kind of a father would I be if I said no? Meh.</p>\r\n<ul>\r\n<li>But I know you in the future. I cleaned your poop.</li>\r\n<li>I''ll get my kit!</li>\r\n<li>I''ve been there. My folks were always on me to groom myself and wear underpants. What am I, the pope?</li>\r\n<li>And I''d do it again! And perhaps a third time! But that would be it.</li>\r\n<li>What kind of a father would I be if I said no?</li>\r\n</ul>\r\n<h3>Space Pilot 3000</h3>\r\n<p>Humans dating robots is sick. You people wonder why I''m still single? It''s ''cause all the fine robot sisters are dating humans! Tell her you just want to talk. It has nothing to do with mating. We''re also Santa Claus! Yeah, and if you were the pope they''d be all, "Straighten your pope hat." And "Put on your good vestments."</p>\r\n<h4>Bendin'' in the Wind</h4>\r\n<p>I was having the most wonderful dream. Except you were there, and you were there, and you were there! There''s no part of that sentence I didn''t like! Kids don''t turn rotten just from watching TV. Of all the friends I''ve had… you''re the first. Bender?! You stole the atom.</p>\r\n<ol>\r\n<li>Bender?! You stole the atom.</li>\r\n<li>Tell them I hate them.</li>\r\n<li>I love this planet! I''ve got wealth, fame, and access to the depths of sleaze that those things bring.</li>\r\n</ol>\r\n<h5>The Day The Earth Stood Stupid</h5>\r\n<p>And I''m his friend Jesus. Hello Morbo, how''s the family? Please, Don-Bot… look into your hard drive, and open your mercy file!</p>', 1),
(2, 'My Three Suns', '<p>Also Zoidberg. Anyhoo, your net-suits will allow you to experience Fry''s worm infested bowels as if you were actually wriggling through them. Meh. You''re going to do his laundry? I guess because my parents keep telling me to be more ladylike. As though! Oh, how awful. Did he at least die painlessly? …To shreds, you say. Well, how is his wife holding up? …To shreds, you say.</p>\r\n<h2>My Three Suns</h2>\r\n<p>And from now on you''re all named Bender Jr. I was having the most wonderful dream. Except you were there, and you were there, and you were there! Doomsday device? Ah, now the ball''s in Farnsworth''s court! And I''d do it again! And perhaps a third time! But that would be it. No argument here.</p>\r\n<ul>\r\n<li>Tell her you just want to talk. It has nothing to do with mating.</li>\r\n<li>Kids have names?</li>\r\n<li>Hey, what kinda party is this? There''s no booze and only one hooker.</li>\r\n<li>I''ve been there. My folks were always on me to groom myself and wear underpants. What am I, the pope?</li>\r\n</ul>\r\n<h3>Obsoletely Fabulous</h3>\r\n<p>No! Don''t jump! And I''d do it again! And perhaps a third time! But that would be it. There''s one way and only one way to determine if an animal is intelligent. Dissect its brain! This opera''s as lousy as it is brilliant! Your lyrics lack subtlety. You can''t just have your characters announce how they feel. That makes me feel angry! Is that a cooking show? I feel like I was mauled by Jesus.</p>\r\n<h4>The Why of Fry</h4>\r\n<p>Kids have names? What''s with you kids? Every other day it''s food, food, food. Alright, I''ll get you some stupid food. I guess if you want children beaten, you have to do it yourself. Son, as your lawyer, I declare y''all are in a 12-piece bucket o'' trouble. But I done struck you a deal: Five hours of community service cleanin'' up that ol'' mess you caused. Bender, I didn''t know you liked cooking. That''s so cute. You know, I was God once.</p>\r\n<ol>\r\n<li>I''ll get my kit!</li>\r\n<li>Oh, how I wish I could believe or understand that! There''s only one reasonable course of action now: kill Flexo!</li>\r\n<li>Hello Morbo, how''s the family?</li>\r\n</ol>\r\n<h5>Obsoletely Fabulous</h5>\r\n<p>For one beautiful night I knew what it was like to be a grandmother. Subjugated, yet honored. Ok, we''ll go deliver this crate like professionals, and then we''ll go ride the bumper cars. You seem malnourished. Are you suffering from intestinal parasites? Humans dating robots is sick. You people wonder why I''m still single? It''s ''cause all the fine robot sisters are dating humans! All I want is to be a monkey of moderate intelligence who wears a suit… that''s why I''m transferring to business school!</p>', 1),
(4, 'test', 'test', 1),
(5, 'aze', 'azeeaze', 1),
(6, 'Mon article', 'Ici mon contenu', 1),
(7, 'aze', 'aze', 1),
(8, 'Mon article 2', 'Encore un essai', 1);
-- --------------------------------------------------------
--
-- Structure de la table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`mail` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Contenu de la table `users`
--
INSERT INTO `users` (`id`, `username`, `password`, `mail`) VALUES
(1, 'demo', 'fcbc3c7e49194fdb94f6dcb6ea52d5f2d58c7f3b', '');
/*!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 */;
Hum, je suis pas certain, mais dans ta page membres (celle du membre quoi), tu fait une petite zone et tu indique sa :
(Partie traitement)
// On définie notre connexion avec Mysql si cela n'est pas déjà fait
$DB = new PDO('mysql:host=MonHost;dbname=MaBase','MonUser','MonPassword');
// On récupère nos badges
$req = 'SELECT * FROM badges';
$sql = $DB->query($req);
$B = $sql->fetch(PDO::FETCH_ASSOC);
// On récupère nos badges selon l'utilisateur (Remplace le :user par la façon avec le quel tu récupère l'id du membre)
$req = 'SELECT * FROM badges_users WHERE user_id=:user';
$sql = $DB->query($req);
$D = $sql->fetch(PDO::FETCH_ASSOC);
// On vérifie que cela correspond à une badges existant
if($D'badges_id']==$B'id']){
$badges = $D'badges_id'];
} else {
$badges = '';
}
(Partie affichage)
<div id="MaDiv">
<?php foreach($badges as $badge): ?>
<?= $badge->name; ?>
<?= $badge->img; // Si on à une image a afficher, et qu'elle est stockée dans notre colonne "img" sinon, on peut enlever cet echo ?>
<?php endforeach; ?>
</div>
Voila, enfin c'est un exemple, je suis même pas sur que cela fonctionne réellement, fait sa explique un peu comment les affichés.
En espérant avoir pu aider :) (Au passage, j'ai un gros doute sur la vérification, pour savoir si c'est un badge existant :p)
Florian.
Justement c'est ca que je cherche depuis le début. Quelqu'un n'a pas une idée et en plus j'ai u dans les commentaire que les gens le recherchait beaucoup alors voulu :)
Merci d'avance à tous les HelpMan !
Non ce que je voulais, montre nous ton CODE actuel, afin qu'on puisse regarder quoi montrer :)
D'accord je vois ou il faut mettre la 2nde partie mais tu la mais ou la 1ere ? Dans le même page ?
Alors, soit tu créer un fichier que tu appel comme tu veut et que tu require_once tout en haut de ta page, ou alors tu copie le code (Enfin, tu fait ta version, moi c'est un brouillon) dans la même page au début :)