Echo PHP variable in Javascript in PHP
<p>This may seem like an odd question, and it may have been answered elsewhere...but frankly I'm not quite sure how to phrase a search any better.</p>

<p>Essentially, I am trying to write an entire HTML and Javascript page in PHP (this way I can easily call and manipulate SQL queries...I know it doesn't make a lot of sense, but it's my last resort for an upcoming deadline). </p>

<p>Anyways, I want to call/append to a PHP variable (the SQL query) in my Javascript...Something like this:</p>

<pre><code>mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$myquery = "SELECT  `xxx`, `yyy` FROM `$tbl_name`";
$query = mysql_query($myquery);
$data = array();

for ($i = 0; $i &lt; mysql_num_rows($query); $i++) {
    $data[] = mysql_fetch_assoc($query);
}

$data1 = json_encode($data);

echo '&lt;!DOCTYPE html&gt;
      &lt;html&gt;
          &lt;head&gt;&lt;/head&gt;
          &lt;body&gt;
              &lt;script&gt;
                  data_arr = {$data1}
                  ...
                  ...
</code></pre>

<p>This doesn't seem to be working though. I've tried:</p>

<pre><code>    data_arr = {$data1}
</code></pre>

<p>and</p>

<pre><code>    data_arr = {'.$data1.'}
</code></pre>

<p>No luck so far. Is there anything I can do?</p>
