2013-06-12 123 views
1

基本上,如果用户想要评论产品,则需要显示该产品的最后评论。如何在同一页面上显示以前的评论

这里是Comment.php代码,这里是插入到数据库中的注释数据,但问题是我想在评论框之后的同一页上显示产品以前的注释。

有什么建议吗?

 <?php 


     include('GenericClasses/GenericCollectionClass.php'); 
     include('Models/UsersModel.php'); 
     include('DataObjects/Users.php'); 





    //If you are not submitting the form HTML will be directly shown 

     if (!isset($_POST['submit'])) 
    { 
    ?> 


    <html> 
     <head> 
    <link href="facebox.css" media="screen" rel="stylesheet" type="text/css" /> 
    <link href="CSS/screen.css" type="text/css" rel="stylesheet" /> 
    </head> 
    <body> 



    <form action="" method="post" name="postsForm"> 
    <div class="UIComposer_Box"> 

    <span class="w"> 
    <textarea class="input" id="watermark" name="watermark" style="height:50px" cols="50" ></textarea> 
    </span>  
    </div> 
    <div align="left" style="height:30px; padding:10px 5px;"> 
      <input type="submit" name="submit" style="background-color: orange;" value="postComment"> 


    </div> 
    <?php   
    } 
    else 
    { 
//If you are submitting the form insert the details into database 

    $Comments = $_POST['watermark']; 

    if (!(empty($Comments))) 
    { 
    $model = new UsersModel(); 

    $rowsCount = $model->InsertComments($Comments); 
    } 
    if ($rowsCount!=0) 
    { 

    echo'Inserted'; 

    } else{ 
     echo 'Not Inserted'; 
    } 


    } 
?> 
    </form> 

    </body> 
    </html> 
+0

传入URL产品ID,消毒值,取记录为ID,环路他们在评论页面 –

+0

使用select查询,并使用max函数来获取先前的评论 –

回答

0

使用以下任何查询。

SELECT row 
FROM table 
WHERE id=(
    SELECT max(id) FROM table 
    ) 

请注意,如果max(id)的值不是唯一的,则会返回多行。 或者试试这个

SELECT row from table ORDER BY id DESC LIMIT 1 
+0

灿我通过使用时间评论..检索评论。 –

+0

分享你的表格结构。如果你有时间在表格中,你可以使用第二个查询 –

相关问题