以模式显示搜索栏查询结果

fjnneemd  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(458)

我有一个搜索栏供用户输入查询。单击“搜索”后,查询结果将显示一个模式。
我的index.php输出仍然没有显示在模式中。当我点击“搜索”时,模态弹出一个空的主体。如何让index.php的输出显示在modal的主体中?
我的剧本有问题吗?我需要在模态体中添加一些东西吗?
索引.php

<head>
  <title>Search</title>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <link rel="stylesheet" type="text/css" href="style.css"/>
 </head>
 <body>
  <form method="POST" action="#">
   <input type="text" name="q" placeholder="Enter query"/>
   <input type="button" name="search" value="Search" data-toggle="modal" data-target="#mymodal">
   </form>
 </body>

<script>
  $.ajax({ type: "GET",
        url: 'search.php',
        success: function(data){ debugger $('#mymodal').modal('show');
        $('#mymodal:visible .modal-content .modal-body').html(e); } });
</script>

 <!-- The Modal -->
<div class="modal" id="mymodal">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Modal Heading</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">

      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>

搜索.php

<?php

  include_once('db.php'); //Connect to database
  if(isset($_REQUEST['q'])){
    $q = $_REQUEST['q'];

    //get required columns
    $query = mysqli_query($conn, "SELECT * FROM `words` WHERE `englishWord` LIKE '%".$q."%' OR `yupikWord` LIKE '%".$q."%') or die(mysqli_error($conn)); //check for query error
    $count = mysqli_num_rows($query);
    if($count == 0){
      $output = '<h2>No result found</h2>';
    }else{
      while($row = mysqli_fetch_assoc($query)){
        $output .= '<h2>'.$row['yupikWord'].'</h2><br>';
        $output .= '<h2>'.$row['englishWord'].'</h2><br>';
        $output .= '<h2>'.$row['audio'].'</h2><br>';
        $audio_name = $row['audio'];
        $output .= '<td><audio src="audio/'.$audio_name.'" controls="control">'.$audio_name.'</audio></td>';
      }
    }
    echo $output;
  }else{
    "Please add search parameter";
  }

  mysqli_close($conn);
?>
yxyvkwin

yxyvkwin1#

使用search.php的以下代码

<?php

    include_once('db.php'); //Connect to database

    if(isset($_REQUEST['q']))
    {
        $q = $_REQUEST['q'];
        $query = mysqli_query($conn, "SELECT * FROM `words` WHERE `englishWord` LIKE '%".$q."%' OR `yupikWord` LIKE '%".$q."%'") or die(mysqli_error($conn)); 
        $count = mysqli_num_rows($query);
        if($count == 0){
          $output = '<h2>No result found</h2>';
        }else{
          while($row = mysqli_fetch_assoc($query)){
            $output .= '<h2>'.$row['yupikWord'].'</h2><br>';
            $output .= '<h2>'.$row['englishWord'].'</h2><br>';
            $output .= '<h2>'.$row['audio'].'</h2><br>';
            $audio_name = $row['audio'];
            $output .= '<td><audio src="audio/'.$audio_name.'" controls="control">'.$audio_name.'</audio></td>';
          }
        }
        echo $output;
      }else{
        "Please add search parameter";
    }

    mysqli_close($conn);
?>

相关问题