I have a problem for displaying the data to HTML using javascript. The code that i create only display the latest data instead of the whole data. I use phonegap in my development. Here is the code:
var oldHtml = document.getElementById("favorite-table-id").innerHTML;
for(var i=0; i<courseIdResult.length;i++) {
//var idResult = courseIdResult[i];
db.transaction(
function(tx) {
var query='SELECT Title,Institution_Id,FullTime,EntryScore,Prerequisites FROM Course WHERE Id='+courseIdResult[i];
tx.executeSql(query,[],function(tx,resultSet) {
console.log("Test 0");
var row = resultSet.rows.item(0);
var newHTML = "<tr> <td> <table> <tr> <td width=1% style='white-space:nowrap;font-weight:bold' align='left'>" +row['Title']+"-"+row['Institution_Id'] +
"</td> <td align='right' style='vertical-align:middle;' rowspan=2> <a href='#'><span class='glyphicon glyphicon-star'></span></a> </td></tr> <tr> <td width=1% style='white-space:nowrap'>" +
"Years:"+row['FullTime']+ " ATAR:"+row['EntryScore']+ " Prereq:"+row['Prerequisites']+
"</td> </tr> </table> </td> </tr>";
document.getElementById("favorite-table-id").innerHTML= oldHtml + newHTML;
},errorCB);
},errorCB
);
}
variable courseIdResult is an ID for my query and i am using loop to get the data. However, everytime the loop progress, the value of document.getElementById("favorite-table-id").innerHTML is always overwrite. Please help me to solve this problem.
Thank you