php - 如何将数据库中的图像调成每行10张图像?

标签 php html mysql image jpeg

<?php

include 'dbconnect.php';

$query = mysql_query("SELECT * FROM champicons") or die("Error: " . mysql_error());

echo "<table border='10' width='100%' cellpadding='10' >"; 
echo "<tr>";  
while($row = mysql_fetch_array($query)) {
    $image = $row[2];
    echo "<td>";
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';   
    echo "<td>";  
}  
echo "</tr>";
echo "</table>";          


?>

我想要实现的目标是将 10 个图像放入 1 行,然后在下面放置一行并显示另外 10 个图像,现在我放入数据库的图像越多,当前行变得越宽越小我看不到所有图像。

很难让它在 10 个图像处创建一个新行,因为图像是在 while 循环中调用的。

最佳答案

在循环之前和循环中添加一个计数器。

$i = 1;
while($row = mysql_fetch_array($query)) { 
    $image = $row[2];
    echo "<td>";
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';   
    echo "</td>";
    if($i++%10 == 0) echo '</tr><tr>';  
}  

关于php - 如何将数据库中的图像调成每行10张图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366692/

相关文章:

php - 如何在 php 中调用 MySQL basedir?

ios - flex-item 中的图像在 Safari、iOS 和 Firefox 中重写 "max-width: none"

python mysql配置问题

php - AFNetworking JSON请求不起作用

php - 带有where子句的laravel 4 updateExistingPivot不起作用

html - 表单输入显示在图像后面

php - 合并具有唯一属性的两行

php - 将图像添加到文件夹并使用 php 将其名称保存在数据库中

php - 如何通过ajax访问json_decode()数据

html - 网站和手机页面的不同 View