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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Mini-chat</title>
</head>
<style>
form
{
text-align:center;
}
</style>
<body>
<form action="minichat_post.php" method="post">
<label for="pseudo">Pseudo</label> : <input type="text" name="pseudo" placeholder= "pseudo" value="<?php if ($_SESSION['pseudo']){ echo $_SESSION['pseudo'];} ?>" /><br />
<label for="message">Message</label> : <input type="text" name="message" id="message" /><br />
<input type="submit" value="Envoyer" />
</p>
</form>
</body>
</html>
<?php
if ( $_SESSION["trouve"] != true) {
echo "Tu es nouveau sur ce mini tchat, je vais faire ton inscription";
} else
{
echo 'Tu es connus sur mini chat ', htmlspecialchars($_SESSION['pseudo']);
}?>
<?php
// Connexion à la base de données
$messagesParPage=10;
//$premiereEntree=0;
//$total=0;
$mindonnee=0;
try
{
$bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'toto');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$conn -> setAttribute ( PDO :: ATTR_EMULATE_PREPARES , false );
$retour_total = $pdo->prepare('SELECT COUNT(*) AS total FROM minichat') ;
$retour_total-> execute ([$min_donnee, $donnees_total]);
$total = $retour_total -> fetchAll ();
$nombreDePages=ceil($total/$messagesParPage);
if(isset($_GET['page'])) // Si la variable $_GET['page'] existe...
{
$pageActuelle=intval($_GET['page']);
if($pageActuelle>$nombreDePages) // Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages...
{
$pageActuelle=$nombreDePages;
}
}
else // Sinon
{
$pageActuelle=1; // La page actuelle est la n°1
}
$premiereEntree=($pageActuelle-1)*$messagesParPage;
//$retour_messages=mysql_query('SELECT pseudo, message, DATE_FORMAT(date_message, \'%d/%m/%Y à %Hh%imin\') AS date_message_fr FROM minichat ORDER BY ID DESC LIMIT '.$premiereEntree.', '.$messagesParPage.'');
$conn -> setAttribute ( PDO :: ATTR_EMULATE_PREPARES , false );
$stmt = $pdo->prepare('SELECT pseudo, message, DATE_FORMAT(date_message, \'%d/%m/%Y à %Hh%imin\') AS date_message_fr FROM minichat ORDER BY ID DESC LIMIT ?,?');
$stmt -> execute ([ $premiereEntree ,$retour_total ]);
$data = $stmt->fetchAll();
$hsc = function($p) { return htmlspecialchars($p); };
while ($data = $stmt->fetch())
{
echo <<<html
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td><strong> Date : {$hsc($data['date_message_fr'])}</strong></td></tr>
<tr><td><strong> Ecrit par : {$hsc($data['pseudo'])}</strong></td></tr>
<tr><td><strong> Message : {$hsc($data['message'])}</strong></p></td></tr>
</table><br /><br />
html;
}
$pages = array_map(function($v) { return ' <a href="minichat.php?page='.$v.'">'.$v.'</a> ';}, range(1, $nombreDePages));
$pages[$pageActuelle - 1] = "[{$pageActuelle}]";
echo '<p align="center">Page : ', implode('', $pages), '</p>';
$reponse->closeCursor();
?>
header('Location: minichat_post.php'); |
Partager