Construction work for Graphics

Asked

Viewed 67 times

-3

I have the following question how can I enter code php within the javascript, that is to say I have a chart made in JS and I want the same to be based on data from my database, how to put the php within the js or I have to get the information from the database from the JS?

For example at the bottom I have the part of the code where you want to fill in the points on the Y axis and I want to fill in instead of having value with values from the database I have already performed the select but how do I put instead of values a while cycle that travels through an Ada table database and enter values.

date: [1,5000,15000,18394,18287,28682,31274,33259,25849,24159,32651,31984,38451]

  • your question is confused, please edit it and insert snippets of code so we can analyze and help you, see how to ask a good question here.

  • I found your question confusing. Your problem is to have Javascript download data that is given by PHP and with that to plot?

1 answer

0


Dude, you can use a repeat loop with php inside javascript, the only thing you need to do is open the php tag inside js when you 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>
  • I already tried that but I could not I am new in php and that is why I am also having difficulties but then write not only put variable?

  • I edited the answer

  • Oh ok, already I realized what I was doing wrong I was putting the tag directly from php just match a variable js thank you that’s right!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.