2015-05-10 24 views
-1

我正在發表可發表評論的帖子,如果帖子似乎附有照片,則會有一個鏈接,您可以點擊該圖片並彈出一個CSS窗口並顯示圖像作爲其內容。始終在while循環中獲取相同的圖像

但是,從數據庫中獲取數據時,我總是得到相同的圖像–爲什麼會這樣?

這裏是我的代碼:

$query="SELECT * FROM post WHERE post_owner IN ($name1) ORDER BY post_id DESC"; 
$queryhandle=$connect->prepare($query); 
$queryhandle->execute(); 
while(my $c=$queryhandle->fetchrow_hashref()){ 
    if("$user_id" eq "$c->{post_owner}"){ 
     $magic_button="<a href=\"delete.pl?p_id=$c->{post_id}\" target=\"_blank\"><button id=\"button_1\">Remove</button></a>"; 
    }else{ 
     $magic_button=""; 
    } 
    HTML::Entities::encode($c->{post}); 
    HTML::Entities::encode($c->{post_attach}); 
    our $post_name="$c->{post_owner}"; 
    my $check_attach=length("$c->{post_attach}"); 
    if($check_attach==0){ 
     our $img_src=""; 
    }else{ 
     our $img_src="<img src=\"$mhost/$c->{post_attach}\" style=\"border-bottom-right-radius: 2pt;border-bottom-left-radius: 2pt;border-top-right-radius: 2pt;border-top-left-radius: 2pt;\"/>"; 
    } 
print <<HTML; 
<table id="post"><td> 
<a href="profile.pl?username=$post_name" style="TEXT-DECORATION:none;color:none;"><img src="$mhost/$c->{post_image}" width="50" height="50" id="image-style"/> <font face="arial" size="4" color="black"><b>$post_name</b></font></a><br /> 
<p style="word-spacing:3px;"> 
$c->{post}<br /> 
<div class="box"> 
    <a class="button" href="#popup1">Let me Pop up</a> 
</div> 

<div id="popup1" class="overlay"> 
    <div class="popup"> 
     <h2>IMAGE</h2> 
     <a class="close" href="#">×</a> 
     <div class="content"> 
      $img_src 
     </div> 
    </div> 
</div> 
</p> 

我每次點擊「讓我彈出」鏈接,我從最近的文章或最新的帖子貼有照片相同的圖像。

+1

'if(「$ user_id」eq「$ c - > {post_owner}」)'沒有引號會好得多。你可以使用'qq()'而不是''''引用(不需要轉義'''')。你也可以從'use strict'使用警告;' –

回答

3

這裏的問題是:

id="popup1" 

id從未迭代之間變化,所以第一個是使用(我看不到任何javascript這裏,所以這是一個猜測,我不太清楚如何它的工作原理)。

此代碼在很多方面都令人生畏,讓我知道你是否想要其他改進建議。

+1

'這個代碼在很多方面都令人震驚。真正的dat! –