【问题标题】:Adding a Hyperlink to MYSQL backed PHP Search Engine向 MYSQL 支持的 PHP 搜索引擎添加超链接
【发布时间】:2014-07-05 05:09:26
【问题描述】:

我是 PHP 新手,一直在研究基于 php 的通用搜索引擎,以便通过 MYSQL 数据库进行搜索。我已经以 goo.gl 格式在谷歌驱动器上存储了建筑物的图片。我的问题是我将如何为数据库中列出的 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>

【问题讨论】:

  • 你能告诉我们你的表架构吗?
  • 您想在列表中生成指向您网站的链接,以显示有关该特定建筑物的详细信息?
  • 或者 url 已经在数据库中了?
  • URL 已经位于数据库中。数据库正在向搜索引擎显示 URL,这正是我想要的,但只是希望这些 URL 可点击并链接到它们在 Google Drive 上的任何位置。我也在努力实现一个更新的 MYSQL 方法。

标签: php html mysql


【解决方案1】:

从数据库中获取 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?

【讨论】:

  • 我将更新 SQL 以防止这种情况发生,但我真正的问题是,可以说数据库中存储的每个 URL 都是不同的,所以每个建筑物都有不同的 URL,它指向,我将如何将每个 URL 拉入 PHP 并使其可点击。图片存储在 google drive 中,URL 直接指向图片。
猜你喜欢
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 2012-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-04
  • 1970-01-01
相关资源
最近更新 更多