Building graphics [closed]

-3

I have the following question how can I insert code php into javascript , ie I have a graph made in JS and I want it to be based on data from my database, like putting php within js or do I have to fetch the database information from JS?

For example the below I have the part of the code where you want to fill in the points on the Y axis and I intend instead to have value fill with values from the database I already made the select but how do I put instead of values a while loop that cycles through a database table and enter the values.

Date: [1.5000,15000,18394,18287,28682,31274,33259,25849,24159,32651,31984,38451]     

asked by anonymous 23.10.2017 / 21:43

1 answer

0

Dude, you can use a loopback with php inside the javascript, the only thing you need to do is open the php tag inside js when you're going to use it.

Ex pass PHP variable to js

<?php  
$conteudo = 'testando';  
?>
<script>
   var conteudo_js = "<?php echo $conteudo; ?>";
   alert(conteudo_js);
</script>

Ex passing For

<?php  
   $array_conteudo = array('conteudo1','conteudo2','conteudo3');
?>
<script>
var conteudo_js = '';
<?php  
  foreach($array_conteudo as $val)
  {
?>
  alert("<?php echo $val; ?>");
<?php
  }
?>
</script>
    
23.10.2017 / 22:13