2011-08-02 156 views
0

mysql_fetch_assoc只取一個記錄
PHP代碼(東西都好檢查數據庫端):mysql_fetch_assoc只返回1個結果

<?php 
$folder_id = $_GET['folder_id']; 
$query = mysql_query("SELECT * FROM gallery_photos WHERE folder_id = $folder_id"); 

if (mysql_num_rows($query) == 0) 
{ 
    echo '<h2>Sorry, you cannot change a folders photo cover if that folder has 
     no photos in it<br /> <a href="gallery.albums.php?fder_id=' 
     .$folder_id.'">Back to the folder</a><h2>'; 
} 
else 
{ 
    while ($row = mysql_fetch_assoc($query)) 
    { 
     echo '<img src="gallery_photos/'.$row['photo_name'].'" width="200"'; 
    } 
} 
?> 
+1

您能告訴我們一些DB數據嗎?你確定它應該返回多行嗎? –

+1

你試過例如mysql_fetch_array與assoc?順便說一句,你的代碼中有一個好奇的sql注入漏洞。 – Zaffy

回答

3

你不關閉HTML IMG標記。將/>添加到您的標記。

echo '<img src="gallery_photos/'.$row['photo_name'].'" width="200" />'; 
+0

哦,親愛的我怎麼沒有看到這一點,我一直這樣做,感謝你的救星m8的快速反應;) – josh

+0

呃,有時候活的儲蓄並不難。從一位開發人員那裏得到一個提示:這是您想要步行30分鐘的時刻。 :) –

+0

然後,縮進你的代碼。良好的美學效果可以幫助您更輕鬆地抓住這些事物 –