2011-05-19 40 views
0

我已經創建了一個數據庫,即newwork和表名屬性。在這個數據庫中,我存儲了用戶詳細信息和一個圖像。現在我想在一個新頁面中顯示來自一個字段的所有數據和來自同一字段的已存圖像。請幫我參加這個項目。這些字段是property_id,屬性,位置,圖像。如何獲取存儲在數據庫中的圖像和數據?

回答

1

你真的需要兩個部分在這裏(一個建立HTML和另一個獲取/顯示圖像):

1部分:HTML生成器

<?php 
    $res = mysqli_query($cnx, 'SELECT property_id, property, location from newwork'; 
    if (res) 
    { 
    while ($row = mysqli_fetch_assoc($res)) 
    { 
     echo '<span class="property">'.$row['property'].'</span>'; 
     echo '<span class="location">'.$row['location'].'</span>'; 
     echo '<span class="photo"><img src="image.php?id='.$row['property_id'].'" /></span> 
    } 
    } 

2部分:圖像生成器

<?php 
    $res = mysqli_query($cnx, 'SELECT image 
          FROM newwork 
          WHERE property_id='.intval($_REQUEST['id'])); 
    if ($res) 
    { 
    $row = mysqli_fetch_assoc($res); 
    if (!empty($row)) 
    { 
     header('Content-Type: image/jpg'); 
     echo $row['image']; 
     exit; 
    } 
    } 
    header('Location: error_image.jpg',TRUE,302); 
相關問題