我尝试在我的网站上制作照片库。我在循环
的图像上建立链接时遇到了一个小问题由于您在此处请求完整代码,因此:
<html>
<head>
<meta charset="UTF-8">
<title>Fotečky</title>
<style>
.foto{
position: relative;
display: inline-block;
text-align: center;
width: 200px;
border: solid;
margin-left: 6%;
}
#date{
position: relative;
text-align: center;
width: 200px;
}
a { color: #000000; text-decoration: none; }
.menu {
background-color: #FF9933;
height: 10%;
line-height: 300%;
}
</style>
</head>
<body>
<div class="menu">
<a href="insert.php"><center><h2>Upload photo</h2></center></a>
</div>
<br>
<?php
mb_internal_encoding("UTF-8");
$connect = mysql_connect("","","") or die("Couldn't connect");
mysql_set_charset('utf8',$connect);
mysql_select_db("") or die("Couldn't find db");
$SQLCommand = "SELECT * FROM foto";
$result1 = mysql_query($SQLCommand); $database = array(); $index = 1; // make a new array to hold all your data
while($row1 = mysql_fetch_assoc($result1)) // loop to give you the data in an associative array so you can use it however.
{
$database[$index] = $row1;
$index++;
}
for ($i=1; $i < count($database); $i++) {
echo '<a href="photo.php?id='.$database[$i]['id'].'">';
echo '<div class="foto">';
echo '<img title="'.$database[$i]['description'].'" alt="'.$database[$i]['description'].'" src="data:image/jpg/png/jpeg;base64,'.base64_encode( $database[$i]['image'] ).'" width="200px"/>';
echo "<div id='date'>".$database[$i]['uploaded']."</div>";
echo '</div>';
echo '</a>';
if ((($i % 4) == 0) && ($i != 0)) {
echo '<br><br>';
}
}
?>
</body>
我希望逐个显示图片并能够点击它们 - &gt;链接,带我到photo.php?id =与该图像的ID。 (id从1到n)
db sructure: enter image description here