2014-02-20 78 views
0

我正在尝试进行图片搜索。它会显示电影的图像,我也希望电影名称显示在图像下方。这是我得到远如何制作图片搜索引擎?

在我phpMy我有5行

ID INT(11)

标题为varchar(100)

说明文字

URL文本

keywords varchar(100)

这是我的搜索ba [R

<div> 
<form action='/search.php' method='GET' style="margin-bottom:1px;"> 
<input id='searchbar' type='text' size='65' name='search' placeholder="search for movies & tv shows"> 
<input id='submit' type='submit' name='submit' value='Search' > 
</form> 
</div> 

,这是结果页面

<html> 
<head> 
<title>FastMegaMedia</title> 
<link rel="icon" href="img/putlockermedia_logo.png" type="image/icon"> 
<link rel="stylesheet" href="Style/index.css" media="screen"> 
</head> 
<body> 

<?php include_once("/php/header.php"); ?> 


     <table id=content width="100%" height="25" border="0" cellpadding="0" cellspacing="0"> 

       <?php include_once("/php/ad1.php"); ?> 

       <td width="63%" valign="top"> 
       <section class="content"> <!-- start of conntent --> 
       <?php 
$x = 0; 
$construct = ''; 

$button = $_GET ['submit']; 
$search = $_GET ['search']; 

if(!$button) 
echo "you didn't submit a keyword"; 
else 
{ 
if(strlen($search)<=1) 
echo "Search term too short"; 
else{ 
echo "You searched for <b>$search</b> <hr size='1'></br>"; 
mysql_connect("localhost","root",""); 
mysql_select_db("search"); 

$search_exploded = explode (" ", $search); 

foreach($search_exploded as $search_each) 
{ 
$x++; 
if($x==1) 
$construct .="keywords LIKE '%$search_each%'"; 
else 
$construct .="AND keywords LIKE '%$search_each%'"; 

} 

$construct ="SELECT * FROM searchengine WHERE $construct"; 
$run = mysql_query($construct); 

$foundnum = mysql_num_rows($run); 

if ($foundnum==0) 
echo "Sorry, there are no matching result for <b>$search</b>.</br></br><li> 
Try more general words. for example: If you want to search 'how to create a website' 
then use general keyword like 'create' 'website'</li><li> Try different words with similar 
meaning</li><li> make sure you are spelling is correct</li>"; 
else 
{ 
echo "$foundnum results found !<p>"; 

while($runrows = mysql_fetch_assoc($run)) 
{ 
$title = $runrows ['title']; 
$desc = $runrows ['description']; 
$url = $runrows ['url']; 

echo " 
<a href='$url'><b>$title</b></a><br> 
$desc<br> 
<a href='$url'></a><p> 
"; 

} 
} 

} 
} 

?> 

</section> <!-- end of conntent --> 
       </td> 

       <?php include_once("/php/ad2.php"); ?> 

      </table> 



</body> 
</html> 

我有什么可以做,使之显示图像,而不是仅仅显示丝毫不差,我知道我失去了一些东西。我是新对此顺便说一句好吧

+0

id你概述你的代码,其更好的可读性 – Rickert

回答

0

首先,你似乎很容易受到SQL injection攻击。永远不要相信未经过处理的用户输入数据。你需要将图像存储在某个地方(我将它作为类型varchar存储在数据库中的路径/文件名),然后在你的PHP代码中输出标题,描述和网址,也只是查询数据库的图片路径和<img src...

0

你错过了图像和对它们的引用(如果在你的数据库中存在的话):

echo " 
<a href='$url'><b>$title</b></a><br> 
$desc<br> 
<a href='$url'></a><br> 
<img class='images' src='$srcOfFoundImage' title='$titleOfFoundImage'><p> 
"; 

如果你没有图像,你can ask Google to find them