title: Making MySQL queries using javascript function.
body: <p>I'm trying to create PHP function that I will be able to use in javascript code.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;?php
  include 'pdo_connect.php';
  function pleaseWork($query) {
      return dataQuery($query)-&gt;fetchAll();
  }
  function makeQuery($query)
  {
      $work = pleaseWork($query);
      $json = json_encode($work);
  }
  ?&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;title&gt;Admin check&lt;/title&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;script type='text/javascript'&gt; 
  &lt;?php makeQuery("SELECT * FROM `grupy`");?&gt;
  
  var jArray = &lt;?= $json ?&gt;;
  console.log(jArray);
  &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p>Of course it doesn't work because code in JS block doesn't know anything about variables from beginning of file. How do I do that? I never used AJAX or anything so I don't know what to do. </p>