<?php include("top.php"); ?>

<?
$req = $bdd->prepare('SELECT cMessages.title, cMessages.message, cMessages.date, cUsers.pseudo FROM cMessages LEFT JOIN cUsers ON cMessages.sender = cUsers.id WHERE user = ?');
$req->execute(array($_SESSION['id']));
while ($data = $req->fetch()) {
    $pseudo = $data['pseudo'];
    if (is_null($data['pseudo'])) {
        $pseudo = "System";
    }
    
    $txt = "<div class='message'><p class='messageTitle'>" . $data['title'] . "</p>From : " . $pseudo . "<br>" . date("d M Y H:i:s", $data['date']);
    
    $txt = $txt . "<p><br>" . $data['message'] . "</p></div>";
    
    echo $txt;
}
?>

<?php include("bottom.php"); ?>