2014-04-11 116 views
-2

大家好我是新來的PHP和做一個項目。我的問題是我正在審查頁面上使用while循環從3個表中獲取數據。回覆評論系統

問題是我想創建評論回覆系統。我正在循環中使用文本區域進行評論,並在按鈕單擊時顯示文本區域,但是當我點擊按鈕時,每個文本區域都可見,我不想要。我認爲問題是由於while循環。 請給我一個正確的想法。 提前感謝您。

PHP的一部分:

<div class="feedback-list"> 

                       <!--img class="doc-img"src="img/doc-img.png" alt="tempimg" height="100"     width="100"/> 
    <div class="feedback-header"-->    
      <?php 
      while($row1=mysql_fetch_array($result1)) 
      { 
       $username1=$row1['username']; 
       $rtitle=$row1['reviewtitle']; 
       $rexperience=$row1['experience']; 

           echo '<div class="feedback"><img class="doc-img" src="img/doc-img.png" alt="temp img" height="100" width="100"/><div class="feedback-header">Rivew by <a href="#"> '.$username1.'</a> 
           <span class="stars" id="star1"><img src="img/stars.png"/></span> 
          </div> 
          <p> '.$rtitle.'</p><br/> 
          <p> '.$rexperience.'</p> 



                     <form action="submitcomment.php" method="post" name="frms"> 
      <!--button type="submit" onclick="showCommentBox()">Reply</button><br/--> 
      <input type="button" value="Reply" onclick="showCommentBox('.$row1['reviewid'].')"><br/> 
      <div class="hidden" id="comment"> 
      <!--p>Comments and suggestions:<br><textarea name="comments" rows="3" cols="30" ></textarea><br><br> 
       <input type="submit" name="sub" value="Confirm"></p--> 
      </div> 
      </form> 



          <span class="read-more">Read  More</span> 
          <span class="added-by">added on 25 March</span> 
         </div>';}?> 

腳本:

<script type="text/javascript"> 
     function showCommentBox(x){ 
      //alert(x); 
     var div=document.getElementById('comment'); 

     div.className='visible'; 

     document.getElementById("comment").innerHTML = 
    '<br/><textarea maxlength="5000" cols="30" rows="3" name="comments"></textarea>' + 
    '<input type="submit" name="sub" value="Confirm">'; 
      } 
    </script> 
+1

哪裏是'ID = 「評論」'textarea的?我沒看到它。 **請**正確地縮進您的代碼。現在很亂。 – David

回答

0

ALL您的評論框具有相同的DOM ID:

<div class="hidden" id="comment"> 
         ^^^^^^^^^^^^ 

這是不允許的。一個ID在整個頁面中必須是唯一的。因此,getElementById()將永遠只返回一個匹配的元素,這通常是它找到的第一個匹配元素 - 沒有必要繼續搜索其中只能存在的元素,對嗎?

你可能想要的東西更像

<div class="hidden" id="comment{$id}"> 

<button onclick="showComment($id);" > 



function showComment(id) { 
    foo = document.getElementById('comment' + id); 
}