title: Bringing data from PHP into D3.JS
body: <p>I have this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var dataset = [ 5, 10, 15, 20, 25 ];
  
          d3.select("body").selectAll("p")
              .data(dataset)
              .enter()
              .append("p")
              .text("New paragraph!");
  &lt;/script&gt;
  </code></pre>
  
  <p>It works. Then I've been learning MySQL/PHP and have some data in a tiny database.</p>
  
  <pre><code>&lt;?php
  if ( $results ) {
  foreach($results as $row) {
      echo $row-&gt;eventName . "&lt;br&gt;";
  }
  } else {
  echo 'No rows found.';
  }
  ?&gt;
  </code></pre>
  
  <p>That works with the rest of it and displays some random event names like Movies, Shopping, Work.</p>
  
  <p>I found <a href="http://www.roseindia.net/tutorial/php/php-variables-javascript.html" rel="noreferrer" title="this tutorial">this tutorial</a> on how to bring PHP variables into Javascript but can't figure it out. To simplify instead of trying to figure out the array I even switched to just trying to figure out the data itself but couldn't even get that. This is what my last attempt was:</p>
  
  <pre><code>    &lt;?php
  $php_var = 1;
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  var dataset = &lt;?php echo $php_var; ?&gt;
  
          d3.select("body").selectAll("p")
              .data(dataset)
              .enter()
              .append("p")
              .text("New paragraph!");
  &lt;/script&gt;
  </code></pre>
  
  <p>And then I thought maybe an array would work so tried this</p>
  
  <pre><code>&lt;?php
  $php_var = array(
      5, 10, 15, 20, 25);
  ?&gt;
  
  &lt;script type="text/javascript"&gt;
  var dataset = $php_var
  
          d3.select("body").selectAll("p")
              .data(dataset)
              .enter()
              .append("p")
              .text("New paragraph!");
  &lt;/script&gt;
  </code></pre>
  
  <p>But also had no luck. Could anyone offer me some advice or point me towards a tutorial on how to get data from PHP into Javascript?</p>