Search code examples
phpdatabasevariablesmicrophone

retrieve a variable value of a div in a database


I try to retrieve a variable value of a div (height) in order to put it in a table of a database in real-time (I absolutely need it). The value of the height is reacting with the microphone of the device. I would scream in the mic of a computer and see the result on another computer. Is there a simple way to do it?

Thanks.

EDIT : Actually I bring back the sound informations with JRecorder (sajithmr.me/jrecorder-jquery). The height of the div is equivalent to the amplitude of the scream. I would put the value of this height in a simple table.


Solution

  • You'll need to throw in some JavaScript in there. I'll use jQuery in my examples.

    To get the height of the div, you can use getClientRects.

    var height = $("#yourdiv")[0].getClientRects()[0].height; //For IE, substract the bottom property from the top property
    

    To send it to the server, you can use AJAX

    $.post("yourpage.php", {height: height});
    

    In your server PHP page, you can then retrieve the value and store it in the DB:

    $height = $_POST['height'];
    

    You now have the value in your database. For another client to see it, you need to make a page that display the latest value and poll that page with AJAX at a set interval to get the value and update your div.

    There is no simple way to do this. This is the most simple I could think of. It still requires a good bit of knowledge of JavaScript and AJAX. If you have any questions leave a comment.