Insert value in javascript from php-mysql

0

Hello, I'm not programmed, but I'm doing a site where I want to put a counter to determine what will be the expiration of the registration of the site. I used the 3D Cube Countdown script, but I would like the date to come straight from php-mysql to be automatic. see part of the code

jQuery(function($){ // on DOM load

//Eg #1
var mycountdown = new cubecountdown({
    containerid: 'futuredate',
  

Here I would like to receive the MYSQL_add date field

targetdate: 'October 17, 2017 11:26:30', 
  

My question

    size: ['10em', '6em'], // specify cube dimensions in "em" only
    unit: ['days']
})
    
asked by anonymous 01.12.2016 / 15:12

1 answer

0

If the query / script is done on the same page you can pass the php string to javascript as follows:

var minhaVarJS = <?=$MinhaVarPHP?>

Before moving on to Javascript use json_encode () in your PHP variable.

If they are done on different pages I recommend using Ajax to retrieve this information.

$.ajax(function(){
    type: "POST",
    url: "suaURL.php",
    data: 'seu-post',
    success: function(data)
        {
            minhaVar = data;
        }
});

And in your PHP page that will receive this post you do the search in the database according to the parameters passed in date: 'your-post', after the search you give

echo json_encode($minhaVarPHP);
    
01.12.2016 / 15:20