2013-06-30 97 views
-4

我想顯示圖像及其說明(懸停)動態地本地主機動態獲取圖像和描述PHP

$c=mysql_connect("localhost","abc","xyz"); 
mysql_select_db("root"); 
q="select * from product"; 
$qc=mysql_query($q); 
while($ans=mysql_fetch_array($qc)) 
{ 
    print "<img id='display_img' src='products/$ans[8]'width=300 height=200>"; 
    print $ans[9] ; 
} 

但這打破每想到。我想在圖像上顯示圖像說明。

我想這

<?php 
       $c=mysql_connect("localhost","abc","xyz"); 
       mysql_select_db("root"); 
       $q="select * from product"; 
       $qc=mysql_query($q); 
       $count=0; 
       while($ans=mysql_fetch_array($qc)) 
        { 
         if($count==0||$count==1||$count==2) 
         { 

          $title=$ans[1]." ".$ans[2]; 
          print '<div class="img-wrap">'; 
          print "<img id='display_img' src='products/$ans[8]'width=300 height=200 title='$title'>"; 
          print '<div class="img-overlay">'; 
          print '<h4>'.$title.'</h4>'; 
          print '<p>'.$ans[9].'</p>'; 
          print '</div>'; 
          print '</div>'; 
         } 
         $count++; 
         if($count==3) 
         { 
          print "<br />"; 
          $count=0; 
         } 
        } 
     ?> 

css code 

.img-wrap 
{ 
height:200px; 
position:relative; 
width:300px; 
margin:10px; 
} 
.img-overlay 
{ 
background-color:#000; 
bottom:0; 
color:#fff; 
height:200px; 
width:300px; 
opacity:0; 
position:absolute; 
z-index:1000; 
transition-duration:0.5s; 
cursor:pointer; 
} 
.img-overlay h4, .img-overlay p{ 
padding:0 10px; 
} 
.img-wrap:hover .img-overlay{ 
opacity:0.75; 
transition:opacity 0.5s; 
} 
b 
{ 
    background-color:#aa490e; 
    color:#fff; 
    font-size:36px; 
    padding: 0 15px; 
    padding-left:65px; 
    padding-bottom:25px; 
    font-family:"Courier New", Courier, monospace; 
} 

它給了我垂直輸出:

http://img707.imageshack.us/img707/4149/kn0b.png

,但我想輸出,如:

http://img441.imageshack.us/img441/8114/it5a.png

+2

通過「這個碎裂每一個想法「你的意思是」它壞了「?如果是這樣,**它是如何破壞** ** – Bojangles

+0

$ ans [8]包含圖像和$ ans [9]包含它的描述 – BhhooHD

+0

要顯示它懸停,你需要使用ajax ..所以你的PHP將獲取內容從數據庫和ajax將呈現懸停抓取的內容 –

回答

0

您是否獲得的圖像和說明在它的旁邊 ?


正如在評論中提及了,你所得到的輸出是每個代碼

,所以你需要從

while($ans=mysql_fetch_array($qc)){ 
    print "<img id='display_img' src='products/$ans[8]'width=300 height=200>"; 
    print $ans[9] ; 
} 

改變你的代碼,以

while($ans=mysql_fetch_array($qc)){ 
{ 
    print "<img id='img_$ans[8]' src='products/$ans[8]' width=300 height=200 title='$ans[9]' >"; 
} 

和正確如果需要,你可以使用jQuery UI的工具提示來顯示描述,其控制方式很多,如

+0

當我嘗試打印desc與圖像它是:http://imageshack.us/photo/my-images/5/3cj9。 PNG /和沒有desc它是:http://imageshack.us/photo/my-images/59/hhmn.png/,我希望當我懸停在圖像上顯示desc – BhhooHD

+0

是的,這是正確的輸出爲每你的代碼 你需要做的是將描述作爲「title」屬性放在圖像中,我會推薦使用jquery ui tooltip以正確的方式顯示描述 – kdeveloper

0

包裹在一個div類的說明/我倒是和使用jQuery來隱藏文本(或CSS效果會更好)剛剛jQuery的懸停效果顯示文本枝條相應的圖像等