2011-11-16 63 views
0

刪除評論選項,讓我有這樣的桌子和兩個SQL語句。我想給的評註3,從第一個查詢,通過使用$ CommentorProfOwnerOpts,它出現在評論部分來自第二查詢被拉出以消除他們的評論的能力。評註者得到的只是對他們的評論

什麼現在的情況是,評註2也獲得了$ CommentorProfOwnerOpts,當時只有3評註者應該讓他們只有對他們的評論。

 
comment_id | comment_title | commentor_id | profile_owner_id 
------------------------------------------------------------- 
    4   Title 1   2    1 
    5   Title 2   3    1  
//Commentor 3 
$commentor = mysql_query("SELECT commentor_id, comment_id FROM comments WHERE commentor_id=3 AND profile_owner_id=1"); 
    $count = mysql_num_rows($commentor); 
    if ($count > 0) { 
     while($row = mysql_fetch_array($commentor)){  
      $commID = $row["comment_id"]; 
      $CommentorProfOwnerOpts = '<span id="remove-'.$commID.'">Remove Comment</span>'; 
    } 

而且這裏的評論:

//All Comments for profile owner 1 
$comments = mysql_query("SELECT comment_id, comment_title FROM comments WHERE profile_owner_id=1"); 
      while($row = mysql_fetch_array($comments)){ 
      $comment_id = $row["comment_id"]; 
      $comment_title = $row["comment_title"]; 
      $CommentorProfOwnerOpts = '<span id="remove-'.$comment_ID.'">Remove Comment</span>'; 

      $comments .= '<div id="$comment_id" class="comments"> 
          '.$comment_title.' 
          '.$CommentorProfOwnerOpts.' 
          </div>' 
    } 

的問題是,我無法弄清楚如何讓每個評註者拿到刪除選項$CommentorProfOwnerOpts,似乎只爲自己的評論,而不是另一個評論。我怎樣才能解決這個問題?

回答

1

不使用某種與會話登錄系統的其中u可以存儲在會話中的用戶ID?

如果u不那麼我勸你否則別指望它會非常難治實現移動你想要

+0

是,評註3在這種情況下 – Maverick

+0

會話ID然後像'如果($ _ SESSION [「身份證」的東西] == $行[ 'commentor_id']){$ CommentorProfOwnerOpts = '<跨度ID =「刪除 - ' $ COMMENT_ID。'」>刪除註釋「; }'應該工作 –

+0

仍然給出評註3上的所有其他評論刪除選項,而不僅僅是他們的:( – Maverick

相關問題