目前,我将有关属性的详细信息存储在数据库中,并使用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);
?>
然而,我想知道我如何能够设置一个图像服务器来存储大量的图像,以便我可以为每个属性引用一个图像,并在结果中以特定的大小显示它的图像。
您可以通过在数据库中添加引用图像名称的另一列来实现这一点。然后将图像名称插入该字段。然后在下面修改了while()
循环,以输出正在调用的行的图像。只要确保循环中所有属性的images源目录相同即可。
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>";
或者,您也可以像上面那样在循环中保存整个路径和引用。