Bonjour a tous, j'ai souvit le tuto du tchat en ajax

Mais j'ai un petit problème, j'ai modifier le code pour mettre le textarea au dessus des message poster, quand je poste un message cela ce met a la suite, donc le dernier, et quand j'actualise sa me le met en premier... j'aimerai modifier le code pour que quand je poste cela reste en premier, proposition !!

Voici le code :

<?php
if(!isset($_SESSION["pseudo"]) || empty($_SESSION["pseudo"])){
header("location:index.php");
}
include "include/connect.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="include/theme/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="include/js/jquery.js"></script>
<script type="text/javascript" src="include/js/tchat.js"></script>
<script type="text/javascript">

<?php
    $sql = "SELECT id FROM messages ORDER BY id DESC LIMIT 1";
    $req = mysql_query($sql) or die(mysql_error());
    $data=mysql_fetch_assoc($req);
?>
var lastid = <?php echo $data["id"]; ?>

</script>
</head>

<body>
<div id="conteneur" style="width:430px;">
<h1>Connectez en tant que <?php echo $_SESSION["pseudo"]; ?></h1>
<div id="connected">

</div>

<div id="tchatForm" style="width:400px;">
<table>
<tr>
<td>
<form method="post" action="#">
<textarea name="message" style="width:300px;"></textarea>
</td>
<td>
<input type="submit" value="Envoyer"/>
</td>
</tr>
</table>
</form>
</div>
<div id="tchat">
<?php
$sql = "SELECT * FROM messages ORDER BY date DESC LIMIT 10";
$req = mysql_query($sql) or die(mysql_error());

    while($data = mysql_fetch_assoc($req)){
    ?>
        <p><strong><?php echo $data["pseudo"]; ?></strong> (<?php echo date("d/m/Y H:i:s",$data["date"]); ?>) : <?php echo htmlentities(utf8_decode($data["message"])); ?></p>
    <?php
    }
 ?>
</div>

</div>

</body>
</html>

Merci

Aucune réponse