Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try {
- $bdd = new PDO("mysql:host=localhost;dbname=chat", "root", "************");
- }
- catch(Exception $e) {
- die($e->getMessage());
- }
- if(isset($_GET["count"])) { //on veut juste l'id du dernier message
- $req = $bdd->query("SELECT id FROM messages ORDER BY id DESC LIMIT 1");
- $data = $req->fetch();
- print $data["id"];
- $req->closeCursor();
- }
- elseif(isset($_GET["depuis"]) AND is_numeric($_GET["depuis"])) { //on affiche les messages ayant un id superieur aux anciens vus
- $req = $bdd->prepare("SELECT * FROM messages WHERE id > ?");
- $req->execute(array($_GET["depuis"]));
- while($data = $req->fetch()) {
- print '<p class="message"><strong>'.htmlspecialchars($data["auteur"]).'</strong> : '.htmlspecialchars($data["post"])."</p>";
- }
- $req->closeCursor();
- }
- else {
- $req = $bdd->query("SELECT * FROM messages");
- while($data = $req->fetch()) {
- print '<p class="message"><strong>'.htmlspecialchars($data["auteur"]).'</strong> : '.htmlspecialchars($data["post"])."</p>";
- }
- $req->closeCursor();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment