我需要帮助开发评论框

时间:2013-11-09 01:32:02

标签: php comments

您好我最近发现如何在php中创建评论框!然而,当有人提交评论时,它会显示在上一条评论之下,我希望新评论显示在上一条评论之上,您也可以告诉我如何使评论框变小?

非常感谢,我希望你能提供帮助:)

<?php
 mysql_connect("mysql10.000webhost.com","a5868186_test","honda33");
 mysql_select_db("a5868186_test");
 $name=$_POST['name'];
 $comment=$_POST['comment'];
  $submit=$_POST['submit'];

 $dbLink = mysql_connect("mysql10.000webhost.com", "a5868186_test", "honda33");
   mysql_query("SET character_set_client=utf8", $dbLink);
  mysql_query("SET character_set_connection=utf8", $dbLink);

if($submit)
 {
if($name&&$comment)
 {
 $insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES 
 ('$name','$comment') ");
 }
 else
 {
  echo "please fill out all fields";
   }
   }
  ?>
 <html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Comment box</title>
  </head>

  <body>
   <center>
   <form action="commentindex.php" method="POST">
  <table>
   <tr><td>Name: <br><input type="text" name="name"/></td></tr>
   <tr><td colspan="2">Comment: </td></tr>
   <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea>   
   </td></tr>
     <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
       </table>
      </form>
    <?php
       $dbLink = mysql_connect("mysql10.000webhost.com", "a5868186_test", "honda33");
      mysql_query("SET character_set_results=utf8", $dbLink);
     mb_language('uni');
      mb_internal_encoding('UTF-8');

     $getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
      while($rows=mysql_fetch_assoc($getquery))
      {
    $id=$rows['id'];
   $name=$rows['name'];
    $comment=$rows['comment'];
     echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>'
   ;}
   ?>

   </body>
  </html>

1 个答案:

答案 0 :(得分:0)

将日期字段添加到MySQL表并在日期字段上排序。