Php Ajax搜索结果和点击结果下载文件

Php Ajax搜索结果和点击结果下载文件,php,sql,ajax,search,livesearch,Php,Sql,Ajax,Search,Livesearch,我的索引页 某个名字 按名称搜索 搜寻 $(文档).ready(函数(){ 加载_数据(); 函数加载\u数据(查询) { $.ajax({ url:“fetch.php”, 方法:“张贴”, 数据:{query:query}, 成功:功能(数据) { $('#result').html(数据); } }); } $(“#搜索_文本”).keyup(函数(){ var search=$(this.val(); 如果(搜索!='') { 加载_数据(搜索); } 其他的 { 加载_数据();

我的索引页


某个名字

按名称搜索
搜寻
$(文档).ready(函数(){ 加载_数据(); 函数加载\u数据(查询) { $.ajax({ url:“fetch.php”, 方法:“张贴”, 数据:{query:query}, 成功:功能(数据) { $('#result').html(数据); } }); } $(“#搜索_文本”).keyup(函数(){ var search=$(this.val(); 如果(搜索!='') { 加载_数据(搜索); } 其他的 { 加载_数据(); } }); });
还有我的fetch.php页面 用于从数据库表中获取数据并输出结果。 我还添加了如果结果>50,它将要求输入更多的字符,因为如果我不添加如果结果>50,那么我的页面需要20秒来显示所有数据,因为我的数据库表有25000个条目

<?php

$connect = mysqli_connect("localhost", "root", "PASSWORD", "DATABASE");
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM files 
  WHERE Name LIKE '%".$search."%'
 ";
}
else
{
 $query = "
  SELECT * FROM files ORDER BY ID
 ";
}
$result = mysqli_query($connect, $query);

if(mysqli_num_rows($result) < 500)
{
 $output1 .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <div>
     <th>Name</th>
     <th>URL</th>
     <th>Extension</th>
    <th>Download</th>
    </div>
 ';

 while($row = mysqli_fetch_array($result))
 {
  $output2 .= '
   <tr>
    <td>'.$row["Name"].'</td>
    <td>'.$row["URL"].'</td>
    <td>'.$row["Extension"].'</td>
   </tr>
  ';
 }
 if(mysqli_num_rows($result) > 0)
 {
    echo "$output1";
    echo "$output2";
 }
else
{
    echo 'no results found';
}
}
else
{
 echo 'Please enter few more charecters';
}

?>

我希望每个结果都有href链接,在单击时,它应该从数据库表的。/“URL”列下载一个文件

我的数据库如下所示:

echo '<td><a href="' . $row['URL'] . '">' . $row["URL"] . '</a></td>';

我的当前页面是


我尝试在outpur'array'中添加如果该字段的内容确实是有效的URL,您应该能够轻松添加
URL
字段以形成有效的URL。我看到您的代码中缺少的是
http
https
(如果是外部链接)。如果它是页面中的相对链接,那么您就可以了。然后添加
以关闭链接。因此,您的表列的形式如下:

echo '<td><a href="' . $row['URL'] . '">' . $row["URL"] . '</a></td>';
echo';

我应该在哪里添加此内容?output2数组结束后?在您的代码中,将“
”.$row[“URL”]。
替换为上面的代码。非常感谢。成功了。但是请你帮我做一件事,我需要一个下载按钮$行['URL']文本。此外,href链接应为mss1996.ddns.net/$行['URL']非常感谢您的帮助
我添加了这个。很好用。