<?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>";
?>
What I'm trying to achieve is for 10 images to be put in 1 row before dropping a row below and making another 10 images appear, right now the more images I put into the database the wider and smaller the current row gets and I can't see all the images.
我想要实现的是将10个图像放在一行中,然后在下面放一行并再生成10个图像,现在我放入数据库的图像越多,当前行的图像越宽越小,我可以看不到所有的图像。
It's hard to get it to create a new row at 10 images as the images are called on a while loop.
由于在while循环中调用图像,因此很难在10个图像上创建新行。
2 个解决方案
#1
1
Add a counter before the loop and if in the loop.
在循环之前添加计数器,如果在循环中。
$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>';
}
#2
0
I think you just need to count your iteration and insert new row according
我想你只需要计算你的迭代并插入新行
$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>";
$i++;
if($i==10){
$i=1;
echo "</tr><tr>";
}
}
As side note your </td>
wasn't closed correctly
另请注意,您的 未正确关闭
#1
1
Add a counter before the loop and if in the loop.
在循环之前添加计数器,如果在循环中。
$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>';
}
#2
0
I think you just need to count your iteration and insert new row according
我想你只需要计算你的迭代并插入新行
$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>";
$i++;
if($i==10){
$i=1;
echo "</tr><tr>";
}
}
As side note your </td>
wasn't closed correctly
另请注意,您的 未正确关闭