目前我在数据库中存储有关属性的详细信息,并使用php将它们加载到html表中,如下所示:
<?php $con=mysqli_connect("localhost:8889","root","root","booksmart_properties");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else{
echo "we connected";
}
if(isset($_POST['submit']))
{
$university = $_POST['university'];
$rent = $_POST['rent']; // i assumed that you name the second Select tag RENT and the Third ROOMTYPE and the last DISTANCE
$roomtype = $_POST['roomtype'];
$distance = $_POST['distance'];
}
// Perform queries
$result=mysqli_query($con,"SELECT * FROM ListedProperties
WHERE PropertyType ='$roomtype' ");
echo "<table border='1'>
<tr>
<th>PropertyType</th>
<th>Description</th>
<th>Rent Price</th>
<th>Location</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['PropertyType'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" . $row['RentPrice'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
但是我想知道如何设置图像服务器来存储大量图像,以便我可以为每个属性引用一个图像,并在结果中以特定大小显示它的图像。
答案 0 :(得分:0)
您可以通过在数据库中添加引用图像名称的另一列来完成此操作。然后将图像名称插入该字段。然后在下面修改了您的while()
循环,以输出被调用行的图像。只需确保图像的源目录对于此循环中的所有属性都相同。
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['PropertyType'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td>" . $row['RentPrice'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "<td>" . "<img src=\"images\"" . $row['PropertyImage'] . " alt=\"" . $row['PropertyImage'] . "\" height=\"42\" width=\"42\"></td>"; //$row['PropertyImage'] = Image.png
echo "</tr>";
或者,您可以像上面一样在循环中保存整个路径和引用。