2013-06-12 97 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

分享你的表格結構。如果你有時間在表格中,你可以使用第二個查詢 –

相關問題