添加超链接到MYSQL支持的PHP搜索引擎

时间:2014-07-04 20:50:20

标签: php html mysql

我是PHP的新手,并且一直在研究基于php的通用搜索引擎,以便搜索MYSQL数据库。我以goo.gl格式存储了google驱动器上的建筑物图片。我的问题是我将如何为数据库中列出的URL创建超链接,因为从大多数情况下,从数据库中提取时链接会有所不同。无论是有可点击链接还是显示图片都会很棒。

<html>
<head>
<title> Buildings</title>
</head>
<center>
<body>


<?php
include "connection.php";

$sql = "SELECT * FROM Building_Loc ";

if (isset($_POST['search'])) {

$search_term = mysql_real_escape_string($_POST['search_box']); 
$sql .= "WHERE Building LIKE '%{$search_term}%' "; 
$sql .= "OR Floor LIKE '%{$search_term}%' "; 
$sql .= "OR Number LIKE '%{$search_term}%' "; 
$sql .= "OR Building_Pictures LIKE '%{$search_term}%' ";
}   

$query = mysql_query($sql) or die(mysql_error());



?>
<form name="search_form" method="POST" action="display_data.php"> 

Search: <input type="text" name="search_box" value="" /> 
<input type="submit" name="search" value="Search">
</form>


<table width="80%" cell padding="60" cellspace="60">

<tr>
   <td><strong>Building</strong></td>            
   <td><strong>Floor</strong></td>
   <td><strong>Number</strong></td>
   <td><strong>Picture</strong></td>

</tr>
<?php while ($row = mysql_fetch_array($query)) { ?>
<tr>
   <td><?php echo $row['Building']; ?></td>              
   <td><?php echo $row['Floor']; ?></td>
   <td><?php echo $row['Number']; ?></td>       
   <td><?php echo $row['Building_Pictures']; ?></td>
</tr>

<?php } ?>

</body>
</center>
</html>

1 个答案:

答案 0 :(得分:0)

从数据库中获取URL字符串,比如我们将其放入变量$ URL,然后

超链接:

<?php echo "<a href =\"{$URL}\">Click to view</a>" ?>

图像:

<?php echo "<img src =\"{$URL}\" />" ?> 

此外,您的代码易受SQL注入攻击;参考How can I prevent SQL injection in PHP?

相关问题