Reputation: 17
Im using MySQL to obtain data into $username
and $chance
.
There are two usernames in the data but it only loads the first one.
var data = [
{
"name" : "<?php echo $username; ?>",
"hvalue" : <?php echo $chance; ?>
},
];
Upvotes: 0
Views: 56
Reputation: 563
To give a correct answer, we'll have to know what your variables $username
and $chance
exactly look like.
json_encode
to make a JSON array from them, before you can add them to your javascript object. (see https://secure.php.net/manual/en/function.json-encode.php)Anyway, the best way to send a PHP array to JS would be to create the whole array in PHP and then encode it to JSON in order to use all the values in JS.
var data = <?php echo json_encode($data); ?>
More advanced: use an ajax request to avoid mixing up PHP an JS. But that's another story.
Upvotes: 1