如何在将新记录添加到数据库时播放声音 [英] How to play sound when new record added to database

查看:76
本文介绍了如何在将新记录添加到数据库时播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP,我想在新记录添加到数据库时播放声音文件,但我只需要播放一次该声音。我尝试下面的代码点击功能&它的工作原理

 <?php 
if(isset($ _ REQUEST [action]))
if($ _ REQUEST [action] ==play)
{
?>
< embed src =Kalimba.mp3autostart =trueloop =falsestyle =width:5px; height:2px;>
<?php
}
?>

当点击播放链接时,它会启动该mp3文件

 < a href =sound.php?action = play>播放< / a> 


解决方案

在网站上播放声音,你会想看看声音管理器2:
http://www.schillmania。 com / projects / soundmanager2 /



如果您在访问者正在查看某个页面时询问如何将新记录添加到数据库中希望进行实时检查和通知),您需要使用ajax来获取最高的id(或用于标识最新记录的东西),并将唯一标识符与javascript与前一个id进行比较。如果它们不匹配,则添加新的记录,您应该触发播放声音。

I'm using PHP, i want to play sound file when new record added to database but i need to play that sound only once. i try below code with click function & it works

<?php
if(isset($_REQUEST["action"]))
if($_REQUEST["action"] == "play")
{
?>
<embed src="Kalimba.mp3" autostart="true" loop="false" style="width:5px; height:2px;">
<?php
}
?>

When click on play link it start that mp3 file

<a href="sound.php?action=play">Play</a> 

解决方案

To play a sound on a website (pretty universally), you'll want to look into sound manager 2: http://www.schillmania.com/projects/soundmanager2/

If you are asking how to know when a new record is added to the database while the visitor is viewing a page (you want live checking and notification), you'll need to use ajax to fetch the highest id (or something to identify the newest record) and compare the unique identifier with javascript to the previous last id. If they do not match, a new record was added and you should trigger playing the sound.

这篇关于如何在将新记录添加到数据库时播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆