title: how to use query results in javascript
body: <p>I'm trying to use results variable from <code>mysql</code> in <code>node.js</code> app.
  I want to use results variable inside <code>connection.query</code> function.
  Can anyone help me?</p>
  
  <pre><code>connection.query(sql, function (error, results) {
      if (error) throw error;
  });
  </code></pre>
  
  <p>EDIT: Sorry, I just want to use it (results inside that connection.query function) outside that function. 
  I have code like this:</p>
  
  <pre><code>var sql= "SELECT count(*) AS hitung FROM information_schema.columns WHERE table_name = 'table' ";
  connection.query(sql, function (error, results) { 
      if (error) throw error; 
  }); 
  </code></pre>
  
  <p>I want to use that results in another function like:</p>
  
  <pre><code>function example() {
      for (i=0; i&lt;results; i++) {
          console.log(i);
      };
  };
  </code></pre>