2016-06-13 71 views
1

大家好,我想在库中的每个不同图像上显示来自数据库的任何类型的信息(This is how it looks),与RedBox非常相似,但我不知道如何去做,有没有人有任何解决方案?如何使用JQuery在图像旁显示数据库信息?

PS:顺便说一句,我使用SQL Server 2008

这是我迄今为止...

的Index.html

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Tablero</title> 
     <link rel="stylesheet" href="css/style.css"> 
     <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    </head> 
    <body> 
     <section class="tagline"> 
      <h1>Jueces</h1> 
     </section> 
     <div id="container"> 
      <h1 id="heading"> Projects</h1> 
      <ul id="gallery"></ul> 
     </div> 
     <script> 
      $(document).ready(function() { 
       setInterval(function() { 
        $("#container").load('connection.php'); 
       }, 1000); 
      }); 
     </script> 

    </body> 
</html> 

Connection.php

<?php 
$server = "localhost"; 
$user = "perron"; 
$password = "hasg"; 
$database = "ejemplo"; 
$conn = odbc_connect("Driver={SQL Server Native Client 10.0}; Server=$server; Database=$database;", $user, $password); 
$sql = "SELECT * FROM Prueba"; 
$rs = odbc_exec($conn, $sql); 
if (!$rs) { exit("Error en la consulta SQL"); 
} 
?> 

<div class="container"> 
    <div id="container"> 
     <h1 id="heading"> Projects</h1> 
     <ul id="gallery"> 
      <?php do{ 
      ?> 
      <?php $resultado_img = odbc_result($rs, "img"); 
      $resultado_id = odbc_result($rs, "id"); 
      $resultado_nombre = odbc_result($rs, "nombre"); 
      $resultado_fecha = odbc_result($rs, "fecha_aud"); 
      $resultado_hora = odbc_result($rs, "hora_aud"); 
      $resultado_juzgado = odbc_result($rs, "juzgado"); 
      ?> 
      <?php echo '<li><img src="img/' . $resultado_img . "\" alt=\"\" height=\"200\" width=\"200\" /></li>"; ?> 
      <?php } 
       while (odbc_fetch_row($rs)) 
      ?> 
     </ul> 
    </div> 
</div> 

的style.css

body { 
    margin: 0; 
    padding: 0; 
    font-family: "Arial", sans-serif; 
    font-size: 15px; 
    color: #666; 
    text-decoration: none; 
    line-height: 1.6em; 
} 
a { 
    color: #666; 
    text-decoration: none; 
} 
.container { 
    width: 80%; 
    margin: auto; 
    overflow: auto; 
} 
.logo { 
    float: left; 
    width: 30%; 
    margin-top: 15px; 
} 
section { 
    padding: 20px 0; 
    overflow: hidden; 
} 
.tagline { 
    background: #03899c; 
    color: #fff; 
} 
.tagline h1 { 
    text-align: center; 
    font-size: 35px; 
} 
#gallery { 
    list-style: none; 
    margin: 0; 
    padding: 0; 
    width: 100%; 
} 
#gallery li { 
    display: block; 
    float: left; 
    width: 23%; 
    cursor: pointer; 
    border-radius: 5px; 
    box-sizing: border-box; 
    margin: 0 12px 7px 0; 
} 
#gallery img { 
    width: 100%; 
    border-radius: 5px; 
} 
+0

究竟出了什么问题用上面的代码? –

+0

上面的代码没有问题,但我不知道如何显示悬停中的数据库信息或像RedBox那样的类似信息,它们在图像旁边的悬停中显示电影的信息,我想在我的代码中做到这一点 –

+0

我已经更新了我的答案,并在屏幕上显示了鼠标旁边的图像旁边的文字演示 –

回答

0

您的代码看起来不错,你Connection.php的,这是重新写(略有不同)用的图像旁数据库信息的样本。

<?php 
$server="localhost"; 
$user="perron"; 
$password="hasg"; 
$database="ejemplo"; 

$conn = odbc_connect("Driver={SQL Server Native Client 10.0}; Server=$server; Database=$database;", $user, $password); 

$sql = "SELECT * FROM Prueba"; 

$rs = odbc_exec($conn, $sql); 
if (!$rs) { exit("Error en la consulta SQL"); } 
?> 

<div class="container"> 
<div id="container"> 
    <h1 id="heading"> Projects</h1> 
    <ul id="gallery"> 
    <?php 
$li = ""; 
while (odbc_fetch_row($rs)) { 
    $resultado_img=odbc_result($rs, "img"); 
    $resultado_id=odbc_result($rs, "id"); 
    $resultado_nombre=odbc_result($rs, "nombre"); 
    $resultado_fecha=odbc_result($rs,"fecha_aud"); 
    $resultado_hora=odbc_result($rs,"hora_aud"); 
    $resultado_juzgado=odbc_result($rs,"juzgado");    
    $li.="<li><img src=\"img/".$resultado_img."\" alt=\"\" height=\"200\" width=\"200\" />"; 
    $li.="<div id=\"info\">".$resultado_nombre; 
    $li.="<br>".$resultado_fecha; 
    $li.="<br>".$resultado_hora; 
    $li.="<br>".$resultado_juzgado."<div></li>"; 
     } 
    echo $li; 
     ?> 
    </ul> 
</div> 
</div> 

显示图像的旁边信息的样本代码段(在你的榜样使用它添加提供的CSS,JS和HTML的变化)

$("#gallery img").on('mouseover',function(){ 
 
$(this).parent("li").find("#info").toggle("show"); 
 
}).on('mouseout',function(){ 
 
$(this).parent("li").find("#info").toggle("hide"); 
 
});
#gallery li{ 
 
display: block; 
 
float: left; 
 
width: 100%; 
 
cursor: pointer; 
 
border-radius: 5px; 
 
box-sizing: border-box; 
 
margin: 0 12px 7px 0; 
 
} 
 
#gallery img{ 
 
width: 25%; 
 
float: left; 
 
border-radius: 5px; 
 
} 
 
#gallery #info { 
 
width: 70%; 
 
float: left; 
 
margin-left:.5em; 
 
display:none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<ul id="gallery"> 
 
<li><img src="https://farm6.staticflickr.com/5548/11874722676_6450fcb8ba_b.jpg" /> 
 
<div id="info"> 
 
id<br>name<br>text<br>text 
 
</div></li></ul>

Fiddle

+0

哇你真的帮了我很多,非常感谢你这正是我正在寻找的东西:D –

+0

@Phantom_strike很高兴这是有帮助的:) –

相关问题