0

I am retrieved value from the database,i want to put my retrieved data in the JavaScript,i am storing my retrieved value like this $data1 =25 , in my JavaScript code instead of data: 50 i want to put the retrieved $data1 =25,can anyone guide to do it ,thanks.

my java script code

(function ($) {
    "use strict";
    $(document).ready(function () {
        if ($.fn.plot) {

var dataPie = [{
                label: "Samsung",
                data: 50
            }

}
});

});
Xavi
  • 2,552
  • 7
  • 40
  • 59
  • first you use jquery or ajax to send data to php, do you php stuff, than echo the result and in jquery you can collect data like `.done(function(response){ alert(response);});` – Dwza Jun 04 '14 at 08:29

1 Answers1

-1

Some like that:

(function ($) {
    "use strict";
    $(document).ready(function () {
        if ($.fn.plot) {
            var dataPie = [{
                label: "Samsung",
                data: <?php echo $data1 ?>
            }];
        }
    });
});
Sergey
  • 5,208
  • 25
  • 36
  • 1
    This requires that the Javascript is inlined, which is bad practice. Don't build Javascript dyncamically. Just query a PHP script from Javascript that returns, for example, JSON. – Ingo Bürk Jun 04 '14 at 08:24
  • @IngoBürk, I know it, thank you. – Sergey Jun 04 '14 at 08:24
  • @Sergey i tried its not working – Xavi Jun 04 '14 at 08:27
  • Downvote: without explanation this answer is useless. Will only work in specific circumstances (JS is generated by a PHP file). – kapa Jun 04 '14 at 08:30
  • @Xavi, you have to learn about pass data from PHP to Javascript: http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript , it's not simple like i wrote – Sergey Jun 04 '14 at 13:51