2015-06-21 104 views
2

我有這樣的代碼應該尋找想象中的MySQL數據庫,我不知道它是否工作,如何從MySQL數據庫中獲取的圖像在PHP

我想要得到的圖像供用戶搜索和發佈他們在html中,我可以這樣做嗎?

這裏是我的代碼

<?php 
    require('connect.php'); 
     if(isset($_POST['submit'])){ 
     if(isset($_GET['go'])){ 
     if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ 
     $name=$_POST['name']; 
     //connect to the database 
     //-query the database table 
     $sql="SELECT * FROM cards WHERE name LIKE '%$searchQuery'"; 
     //-run the query against the mysql query function 
     $result=mysql_query($sql); 
     //-create while loop and loop through result set 
     while($row=mysql_fetch_array($result)){ 
       $name = $row['name']; 
       $id = $row['id']; 
     } 
     } 
     else{ 
     echo "<p>Please enter a search query</p>"; 
     } 
     } 
     } 
    ?> 
+0

你存儲在數據庫中的圖像的路徑? –

+0

@SulthanAllaudeen是的,像這樣存儲的圖像,文件名/ pictureName.jpg – mazinAlmas

+0

我可以知道你使用的coloumn名稱 –

回答

1

要顯示的圖像[如果您存儲在數據庫中的圖像的路徑]

您應該只是附和coloumn與圖像標籤

echo "<img src =".$row['name'].">"; 

備註:

您應該指向的圖像在圖像存儲在文件

路徑

有些東西一樣

echo "<img src ='assets/images/".$row['name']."'>" 
相關問題