2014-05-03 50 views
-2

我想從數據庫檢索圖像,並希望像一個數據庫中有20個圖像一樣顯示它,那麼它應該顯示在5行,每行包含4個圖像... 我的代碼正在工作正確,但我面臨圖像路徑問題,因爲我高保存圖像名稱在數據庫和圖像裏面的管理/上傳文件夾....像上傳文件夾是在管理文件夾內... adminfolder/uploadsfolder /文件名如何從數據庫中連續顯示圖像?

在這裏我的代碼我在跟蹤圖像路徑越來越問題.....

我在這一行面臨的問題.. //我所有的圖片是在管理/上傳文件夾

echo "<td><img src=\"".$path[$i]."\" height='100'/></td>"; 

這裏是我完整的代碼

<?php 
mysql_connect('localhost','root','') or die(mysql_error()); 
mysql_select_db('dogs_db') or die(mysql_error()); 

$sql = "SELECT file_name FROM dogsinfo"; 
$res = mysql_query($sql) or die(mysql_error()); 
echo "<table><tr>"; 
while($fetch = mysql_fetch_assoc($res)) { 
$path[] = $fetch['file_name']; 
} 

for($i=0;$i<count($path);$i++){ 

if($i%4 == 0){ 
echo "</tr>"; 
} 
// I am Facing Problem here ... 
// my all images is in admin/uploads folder 

echo "<td><img src=\"".$path[$i]."\" height='100'/></td>"; 

} 
echo "</tr></table>"; 
?> 

請幫我弄清楚這個....

+0

返回'$ path [$ i]'包含'admin/uploads/file_name'? –

回答

0

如何在admin/uploads文件夾中,你必須把在img標籤的src

<?php 
mysql_connect('localhost','root','') or die(mysql_error()); 
mysql_select_db('dogs_db') or die(mysql_error()); 

$sql = "SELECT file_name FROM dogsinfo"; 
$res = mysql_query($sql) or die(mysql_error()); 
echo "<table><tr>"; 
while($fetch = mysql_fetch_assoc($res)) { 
$path[] = $fetch['file_name']; 
} 

for($i=0;$i<count($path);$i++){ 

if($i%4 == 0){ 
echo "</tr>"; 
} 
// I am Facing Problem here ... 
// my all images is in admin/uploads folder 

echo "<td><img src=\"admin/uploads/".$path[$i]."\" height='100'/></td>"; 

} 
echo "</tr></table>"; 
?> 
+0

感謝Henrique的工作.... – Pavan