2016-10-14 29 views
0

檢索在我存儲在數據庫中有關屬性的細節瞬間並將其加載到了使用PHP的HTML表,如下圖所示:如何存儲大量的圖像和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

您可以通過在數據庫中添加引用圖像名稱的另一列來完成此操作。然後將圖像名稱插入該字段。您的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>"; 

或者,您可以像上面一樣在循環中保存整個路徑和引用。