2014-03-25 26 views
0

我想顯示存儲在數據庫中的所有圖片我的圖片..然後我的問題是,只有小方會出現。我需要幫助..無法顯示存儲在數據庫中

我maincontent.php

<?php 
    error_reporting(E_ALL); 
    $link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); 
    mysql_select_db("login") or die(mysql_error()); 
    $sql = "SELECT id FROM products"; 
    $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); 
    while($row=mysql_fetch_assoc($result)){ 
    echo '<img src="t2.php?id='.$row['id'].'"/>'; 
    } 
    mysql_close($link); 
     ?> 

我t2.php

<?php 
error_reporting(E_ALL); 
if(isset($_GET['id']) && is_numeric($_GET['id'])) { 

$link = mysql_connect("localhost", "root", "") or die("Could not&amp;nbsp;connect: " . mysql_error()); 

mysql_select_db("login") or die(mysql_error()); 

$sql = "SELECT photo FROM products WHERE id={$_GET['id']}"; 

$result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); 

header("Content-type: image/jpeg"); 
echo mysql_result($result, 0); 
mysql_close($link); 
}else{ 
echo 'Please use&;nbsp;a real id number'; 

} 
?> 

我希望有人能幫助我關於這個問題。

+0

即時通訊使用blob保存圖像在數據庫中。 輸出是:https://dl.dropboxusercontent.com/u/87636874/Capture.JPG – user2699948

+0

當您在瀏覽器中手動打開't2.php?id = SOMEID'時,您會得到什麼?你應該檢查一下,因爲你正在使用'echo'來處理你的錯誤,並且你看不到''標籤中的那些標籤。 –

+0

我找不到錯誤。你確定這個blob被正確保存了嗎?你能提供幾行mysqldunp嗎? – blue

回答

-1

更改爲此。你的t2.php

<?php 
    $imageId = intval($_GET["id"]); 

    $query = mysql_query("SELECT img FROM images WHERE id = ". $imageId); 
    $row = mysql_fetch_array($query); 

    $mime = null; 
    // place $type init. here 
    if ($type=="pjpeg") // <<< where do you get $type btw? 
     $mime = "image/jpeg"; 

    $b64Src = "data:".$mime.";base64," . base64_encode($row["img"]); 
    echo '<img src="'.$b64Src.'" alt="" />'; 
    ?> 
+0

如何幫助他使用'echo'';'顯示圖像? –

+0

是我要更新這個東西....感謝指出[email protected] – Abhishek

0

我不知道你是如何將圖像保存到數據庫(直接圖像或圖像路徑)的。但似乎你必須要改變的那些:

改變這一行:

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

到:

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

和你t2.php

變化:

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

$result = mysql_query($sql) or die("Invalid query: " . mysql_error()); 

你需要使用mysqli_*PDOmysql_*所有函數都被棄用。

相關問題