title: sequence of select query not right
body: <p>I tried to query my database for data. However, when I query for my data, I only managed to get the data after my last alert, which is the <code>alert("Total...")</code> For instance, I run the code below, the alert for "result row:" only appear after the last alert appear. May I know why?</p>
  
  <pre><code>function (result) {
  
             window.location.href = "#/app/CustHomePage";
  
             var totalBalance = 0;
             var tableRef = document.getElementById("myList").getElementsByTagName("tbody")[0];
  
  
  
             for (var i = 0; i &lt; tableRef.rows.length; i++) {
  
                 alert(tableRef.rows[i].cells[3].innerHTML.substr(1));
  
                 var addBalance = parseInt(tableRef.rows[i].cells[3].innerHTML.substr(1));
                 totalBalance = totalBalance + addBalance;
             }
  
             alert(totalBalance);
             var myText = result.text;
             var myTextTwo = myText.replace(/['"]+/g, '');
             alert(myTextTwo);
             var custBal;
  
  
  
             var myDB = window.sqlitePlugin.openDatabase({ name: "mySQLite.db", location: 'default' });
  
             alert("Hello");
  
             myDB.transaction(function(transaction) {
                 alert("Hello");
                 transaction.executeSql("SELECT customerBalance FROM customer where nric = '" + myTextTwo + "'", [], function (tx, results) {
                     var len = results.rows.length;
                     for (var i = 0; i &lt; len; i++) {
                         custBal = results.rows.item(i).customerBalance;
                         alert("result row" + results.rows.item(i).customerBalance);
                         alert("CustomerBal" + custBal);
                     }
                 },
                   function(tx, error)
                   {
  
                   }
                     );
             });
  
  
  
             alert("Total after entitled discount: ");
             alert("Transaction successful, Next Customer Please");
  
         }
  </code></pre>