title: Nested HTML5 Web SQL Query Issued after Entire For Loop Processed
body: <p>In this query listed below, my for loop is executing 4 values. In the first alert(id), it is alerting those 4 distinct values.  However, in the nested query, the alert statement is printing out the last id value only, 4x with different max(b.id) values.  I'm confused.  Does anyone know what may be happening?  Could a race condition be occurring?  </p>
  
  <p>My goal is to place an Ajax call in the nested query, which has input values based on both id and b.id.  I am currently doing this, but the value in the ajax call for the "id" is the same for all 4 different calls, which messes up the return data.  Thanks.</p>
  
  <pre><code>database.db.transaction(function (tx) {
              tx.executeSql('SELECT id, name from programs d', [], function (tx, results) {
                  for (var i = 0; i &lt; results.rows.length; i++) {
                      var id = results.rows.item(i)['id'];
                      var name = results.rows.item(i)['name'];
                          alert(id);
  
                      tx.executeSql('SELECT max(b.id) + 1 max from people b where b.sid = ?',
                          [id],
                          function (tx, results) {
                              lastRecord = results.rows.item(0)['max'];
                              alert(id + "last rec: " + name);
                          }
                      );
                  }
              },
              function (event) { alert(event.message); });
  </code></pre>