简体   繁体   English

PHP从mySQL数据库查询音频文件

[英]PHP query audio files from mySQL database

I have audio files uploaded to my PHP website. 我有音频文件上传到我的PHP网站。 I have a mySQL database connected to the website with a table as shown in the screenshot in the following link: mySQL Table Screenshot 我有一个用表连接到网站的mySQL数据库,如以下链接的屏幕快照所示: mySQL Table屏幕快照

Right now, when you enter a search on the website, it returns the corresponding yupikWord, englishWord, and audio entry from the table in the database. 现在,当您在网站上输入搜索内容时,它将从数据库表中返回相应的yupikWord,englishWord和音频条目。 The audio entry is the name of the audio file located on the web server. 音频条目是位于Web服务器上的音频文件的名称。

I need help: how do I make it so it returns the audio recording if it knows the name of the audio file located on the web server? 我需要帮助:如果知道网络服务器上音频文件的名称,该如何使其返回音频记录?

Here is my PHP code for the mySQL query: 这是mySQL查询的PHP代码:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors',1);

    include_once('db.php'); //Connect to database
    if(isset($_POST['q'])){
        $q = $_POST['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>';
  }
}
echo $output;
}else{
"Please add search parameter";
}
mysqli_close($conn);
?>

Here is HTML code for the search bar on my website: 这是我网站上搜索栏的HTML代码:

<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="search.php">
  <input type="text" name="q" placeholder="Enter query"/>
  <input type="submit" name="search" value="Search" />
</form>
</body>

If you put your audio in , the result will be text, not audio. 如果将音频放入,结果将是文本,而不是音频。 So you need to put your audio link in tag like this 因此,您需要将音频链接放在这样的标签中

<audio controls>
  <source src="/link/to/mp3/<?php echo $row['audio'] ?>" type="audio/mpeg">
</audio>`

Hope this help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM