Question: I'm making an application using PHP, and I wanted to build a really simple page where a sound is played if two values in a MySQL row are set to '1' (true).

For instance, if none or only one of the values is set to 1, the script does not play the sound. 

However, as soon as the second value changes to 1, there should be a JS 'listener' which detects this and automatically plays the sound.

Is there any way to achieve this?

Answer: 
It can be done using webSockets by pushing a message to client side. here is a solution for [implementing webSockets in php](http://socketo.me/).

Also here is a good answer for [How to create websockets server in PHP](https://stackoverflow.com/a/14515205/205997) if you want to do it yourself.
But I can tell you that using php as webSocket server is not going to scale well if your user base is huge. You may want to consider doing it using [Node.js](http://nodejs.org/).

Another option: 
You can also check for update using ajax from time to time. but it will not be as instantaneous as webSocket solution. In this solution the server will receive 1 req per user each x seconds.
PHP is a server side script and it's execute on the server while the JS is client side script.
You can check for the values from the DB in php and if the two values are 1 && 1 you echo a 

```
    <script type="text/javascript">
    <!--play the sound function-->
    </script> 

```

otherwise
you echo empty function