title: Passing PHP $result data to Javascript
body: <p>Here is PHP code that I am using to read values from my MySQL database.</p>
  
  <p>I am accesing the values stored in my table 'data'. I want to read all the data present in the column 'val' and them pass them to JavaScript.</p>
  
  <pre><code>&lt;?php
  mysql_connect("localhost", "root", "root") or die(mysql_error()); 
  mysql_select_db("db") or die(mysql_error()); 
  
  $query = "SELECT data.val from data"; 
  
  $i=0;    
  $result = mysql_query($query) or die(mysql_error());
  
  $i=0;    
  $result = mysql_query($query) or die(mysql_error());
  while ($row = mysql_fetch_array($result))
  {
  echo $row[$i];
  echo "&lt;br /&gt;";
  }
  
  ?&gt;
  </code></pre>
  
  <p>I now want to pass the values in $result to JavaScript, I am plotting a graph with the values by making use of D3.js. </p>
  
  <p>Once posted I am making use of a var array store the points that need to be plotted on the graph. </p>
  
  <p>How do I post the data from PHP to JavaScript?</p>