title: Passing javascript variable into PHP and making mysql query
body: <p>I've the following script (taken from a large script) saved as example3.php:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var layer;
  
  //where layer is a table like 
  ------------------------------------
  BUSNAME       +    Category    +
  ------------------------------------
  200 Bay       +   Restaurant   +
  201 Bay       +   Bank         +
  202 Bay       +   School       +
  203 Bay       +   Restaurant   +
  204 Bay       +   School       +
  205 Bay       +   Restaurant   +
  206 Bay       +   Restaurant   +
  207 Bay       +   School       +
  208 Bay       +   Restaurant   +
  209 Bay       +   Restaurant   +
  ------------------------------------
  
  window.location.href = "example3.php?layer="+ layer;
  
  &lt;?php
    //Make a MySQL Connection
    $query = "SELECT Category, COUNT(BUSNAME) 
      FROM ".$_GET['layer']." GROUP BY Category"; 
    $result = mysql_query($query) or die(mysql_error());
    //Print out result
    while($row = mysql_fetch_array($result)){
      echo "There are ".$row['COUNT(BUSNAME)']. " " .$row['Category']. "items.";
    echo "&lt;br/&gt;";
    }
  ?&gt;
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Don't no why it is not working. Any suggestion must be appreciated. </p>