title: Parsing MySQL into JavaScript Arrays through PHP and jQuery
body: <p><strong>Ultimate Goal: I want to take data I keep in a MySQL Database and put it into an Array of Arrays in JavaScript, so it can be manipulated client side.</strong> </p>
  
  <p>So far, I have been able to pull data from my database with this code:</p>
  
  <pre><code>&lt;?php
  ...
  $num=1;
  
  $q = "SELECT blah1, blah2, blah3 WHERE blah4=$num";
  
  $sth = mysqli_query ($database, $q);
  $rows = array();
  while($r = mysqli_fetch_assoc($sth)) {
      $rows[] = $r;
      }
  
  print json_encode($rows);
  
  ?&gt;
  </code></pre>
  
  <p>(from: <a href="https://stackoverflow.com/questions/383631/json-encode-mysql-results">JSON encode MySQL results</a>)</p>
  
  <p>This is where I am stuck, because I am having trouble getting this data into JavaScript.</p>
  
  <p>One solution I can find is <a href="https://stackoverflow.com/questions/3575636/parsing-a-separate-php-array-in-javascript">Parsing a Separate PHP Array in Javascript</a>:</p>
  
  <pre><code>&lt;script&gt;
       var jsonarray = &lt;?php echo json_encode($array); ?&gt;;
       // now you can use jsonarray in your javascript
  &lt;/script&gt;
  </code></pre>
  
  <p>But the problem with this implementation is that it would spit out all of the database content I query onto the source-code of the page. If I have to do this, I might as well skip the database and just keep all of the content in javascript.</p>
  
  <p>I am thinking there must be a way with jQuery/AJAX to pass the value of $num to a PHP script, grab this data and put it into a JavaScript Array without having to output all of it to the page.</p>
  
  <p>Any assistance would be appreciated.</p>
  
  <p>Thank you!</p>