我已經在我的數據庫中設置了一個圖像表,將我的圖像存儲爲blob類型。我的問題是,我不知道如何在我的網頁搜索頁面顯示數據庫中的圖像。每當我輸入searh查詢時,它都會顯示關鍵字&圖像名稱,但它不會顯示圖像本身。而是顯示長的sql代碼。如何顯示來自我的數據庫的圖像? (php)
這是我的php代碼Imagesearch.php;
<style type="text/css">
body {
background-color: #FFF;
}
</style>
<?php
//get data
$button = $_GET['submit'];
$search = $_GET['search'];
$x = "";
$construct = "";
if (!$button){
echo "You didint submit a keyword.";
}
else{
if (strlen($search)<=2) {
echo "Search term too short.";
}
else {
echo "You searched for <b>$search</b><hr size='1'>";
//connect to database
mysql_connect("localhost","root","");
mysql_select_db("searchengine");
//explode our search term
$search_exploded = explode(" ",$search);
foreach($search_exploded as $search_each) {
//constuct query
$x++;
if ($x==1) {
$construct .= "keywords LIKE '%$search_each%'";
}
else {
$construct .= " OR keywords LIKE '%$search_each%'";
}
}
//echo out construct
$construct = "SELECT * FROM images WHERE $construct";
$run = mysql_query($construct) or die(mysql_error());
$foundnum = mysql_num_rows($run);
if ($foundnum==0) {
echo "No results found.";
}
else {
echo "$foundnum results found!<p>";
while ($runrows = mysql_fetch_assoc($run)) {
//get data
$name = $runrows['name'];
$image = $runrows['image'];
echo "
<b>$name</b><br>
$image<br>
";
}
}
}
}