2017-08-31 67 views
0

我有一个问题,我需要帮助。基本上我试图从数据库中查询信息到新闻动态样式类型的数组。我可以让文本显示出来,但不能显示图像,因为它是BLOB格式。我试图在PDO中编写代码,但我仍然是一个新手。我阅读了大量有关获取blob图像并显示它们的文章。但是大多数文章都提供了弃用代码的说明。任何人谁可以协助将不胜感激。这是我的源代码如下。如何在递归数组中显示blob图像?

<style style="text/css"> 
.scroll-up { 
height: 500px; 
width: 400px; 
overflow: hidden; 
position: relative; 
background: yellow; 
color: black; 
border: 1px solid black; 
} 
.scroll-up p { 
position: absolute; 
width: 400px; 
padding-right: 100%; 
height: 100%; 
margin: 0; 
line-height: 50px; 
text-align: center; 
/* Starting position */ 
-moz-transform:translateY(100%); 
-webkit-transform:translateY(100%);  
transform:translateY(100%); 
/* Apply animation to this element */ 
-moz-animation: scroll-up 20s linear infinite; 
-webkit-animation: scroll-up 20s linear infinite; 
animation: scroll-up 20s linear infinite; 
} 
.clones_wrapper { 
height: 500px; 
width: 400px; 
overflow: hidden; 
position: relative; 
background: yellow; 
color: black; 
border: 1px solid black; 
} 


/* Move it (define the animation) */ 
@-moz-keyframes scroll-up { 
0% { -moz-transform: translateY(100%); } 
100% { -moz-transform: translateY(-100%); } 
} 
@-webkit-keyframes scroll-up { 
0% { -webkit-transform: translateY(100%); } 
100% { -webkit-transform: translateY(-100%); } 
} 
@keyframes scroll-up { 
0% { 
-moz-transform: translateY(100%); /* Browser bug fix */ 
-webkit-transform: translateY(100%); /* Browser bug fix */ 
transform: translateY(100%);  
} 
100% { 
-moz-transform: translateY(-100%); /* Browser bug fix */ 
-webkit-transform: translateY(-100%); /* Browser bug fix */ 
transform: translateY(-100%); 
} 
} 
</style> 

<div class="clones_wrapper"> 

<h2 align='center'>Clones</h2> 

<table style = width:400px;><tr><th>Strain</th><th>Type</th><th>Rating</th><th>Price</th></tr></table> 

<div class="scroll-up"> 
<p><?php 


    echo "<table>"; 
    echo "<marquee behavior='scroll', direction='up'></marquee>"; 

    class TableRows extends RecursiveIteratorIterator { 
    function __construct($it) { 
     parent::__construct($it, self::LEAVES_ONLY); 
    } 

    function current() { 
     return "<td align='center' style='width:150px;'>" . parent::current(). "</td>"; 
    } 

    function beginChildren() { 
     echo "<tr>"; 
    } 

    function endChildren() { 
     echo "</tr>" . "\n"; 
    } 

} 

$servername = "localhost"; 
$username = "root"; 
$password = ""; 
$dbname = "clonemenudb"; 

try { 
    $conn = new PDO("mysql:host=$servername;dbname=clonemenudb", $username, $password); 
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $stmt = $conn->prepare("SELECT strain, type, imagefile, price FROM clones_db"); 
    $stmt->execute(); 


    // set the resulting array to associative 
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); 
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { 
     echo $v; 
    } 


} 
catch(PDOException $e) { 
    echo "Error: " . $e->getMessage(); 
} 
$conn = null; 
echo "</table>"; 

?> 


</p> 

    </div> 
</div> 
+0

我今天解决了这个答案! –

回答

0
<style style="text/css"> 
.scroll-up { 
height: 500px; 
width: 400px; 
overflow: hidden; 
position: relative; 
background: yellow; 
color: black; 
border: 1px solid black; 
} 
.scroll-up p { 
position: absolute; 
width: 400px; 
padding-right: 100%; 
height: 100%; 
margin: 0; 
line-height: 50px; 
text-align: center; 
/* Starting position */ 
-moz-transform:translateY(100%); 
-webkit-transform:translateY(100%);  
transform:translateY(100%); 
/* Apply animation to this element */ 
-moz-animation: scroll-up 20s linear infinite; 
-webkit-animation: scroll-up 20s linear infinite; 
animation: scroll-up 20s linear infinite; 
} 
.clones_wrapper { 
height: 500px; 
width: 400px; 
overflow: hidden; 
position: relative; 
background: yellow; 
color: black; 
border: 1px solid black; 
} 


/* Move it (define the animation) */ 
@-moz-keyframes scroll-up { 
0% { -moz-transform: translateY(100%); } 
100% { -moz-transform: translateY(-100%); } 
} 
@-webkit-keyframes scroll-up { 
0% { -webkit-transform: translateY(100%); } 
100% { -webkit-transform: translateY(-100%); } 
} 
@keyframes scroll-up { 
0% { 
-moz-transform: translateY(100%); /* Browser bug fix */ 
-webkit-transform: translateY(100%); /* Browser bug fix */ 
transform: translateY(100%);  
} 
100% { 
-moz-transform: translateY(-100%); /* Browser bug fix */ 
-webkit-transform: translateY(-100%); /* Browser bug fix */ 
transform: translateY(-100%); 
} 
} 
</style> 

<div class="clones_wrapper"> 

<h2 align='center'>Clones</h2> 

<table style = width:100%;><tr><th>Strain</th><th>Type</th><th>Rating</th><th>Price</th></tr></table> 

<div class="scroll-up"> 
<p><table style = width:100%; cellpadding="0" cellspacing="0" border="0"> 


          <tbody> 
          <?php 
           require_once('db.php'); 
           $result = $conn->prepare("SELECT * FROM tbl_image ORDER BY tbl_image_id ASC"); 
           $result->execute(); 
           for($i=0; $row = $result->fetch(); $i++){ 
           $id=$row['tbl_image_id']; 
          ?> 
           <tr> 
           <td style="text-align:center; word-break:break-all; width:150px;"> <?php echo $row ['strain']; ?></td> 
           <td style="text-align:center; word-break:break-all; width:100px;"> <?php echo $row ['strain_type']; ?></td> 
           <td style="text-align:center; margin-top:10px; word-break:break-all; width:100px; line-height:50px"> 
            <?php if($row['rating'] != ""): ?> 
            <img src="uploads/<?php echo $row['rating']; ?>" width="75px" height="18px"> 
            <?php else: ?> 
            <img src="images/default.png" width="75x" height="18px"> 
            <?php endif; ?> 
           </td> 
           <td style="text-align:center; word-break:break-all; width:100px;"> <?php echo $row ['strain_price']; ?></td> 
           </tr> 
           <?php } ?> 
          </tbody> 
         </table> 


</p> 

    </div> 
</div>