admin管理员组文章数量:1401134
I have a store and I want to play a sound just after receiving an order. I store my orders in my database so I want to play a sound after running this check order query:
$order_check_query("SELECT * FROM orders WHERE status = 'pending'");
I want to run this query every 5 minutes when I am logged in. If there are any pending orders I want to play a sound for 30 sec to notify me.
I have a store and I want to play a sound just after receiving an order. I store my orders in my database so I want to play a sound after running this check order query:
$order_check_query("SELECT * FROM orders WHERE status = 'pending'");
I want to run this query every 5 minutes when I am logged in. If there are any pending orders I want to play a sound for 30 sec to notify me.
Share Improve this question edited Aug 13, 2011 at 2:55 Dan Grossman 52.4k10 gold badges115 silver badges101 bronze badges asked Aug 13, 2011 at 2:49 hamp13hamp13 833 silver badges8 bronze badges 2- 6 PHP is executed server side and has no impact client side. You would have to use Javascript (with AJAX) to re-send the query and to play the sound. – Vincent Savard Commented Aug 13, 2011 at 2:51
- Alright, so let's re-tag this question JavaScript and get him an answer! – Dan Grossman Commented Aug 13, 2011 at 2:55
2 Answers
Reset to default 6Create an audio
element:
var audio = document.createElement('audio');
Insert it into the body:
document.body.appendChild(audio);
Set the sound you wish to play:
audio.src = 'path/to/filename.ogg';
Whenever a query finishes, play the sound:
audio.play();
Example that plays a sound every five seconds with setInterval
: http://jsbin./uravuj/4
So for whatever page you're on, you'd add an ajax function that fires the PHP script that does the query. If it returns true, trigger a javascript function that plays the sound. If it returns false, no sound. Here is an example with jquery:
function checkOrders()
{
$.get('checkOrders.php', function(data) {
if(data.neworders == true) {
audio.play();
}
}
});
t=setTimeout("checkOrders()",(5 * 60 * 1000));
}
$(function() {
checkOrders();
});
This assumes that you are returning the data from php as json and that you have already built an audio object as suggested earlier by Delan.
My javascript/jquery is a bit rusty, feel free to ment or edit mistakes.
本文标签: phpHow can I play a sound after a queryStack Overflow
版权声明:本文标题:php - How can I play a sound after a query? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744235794a2596547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论