admin管理员组文章数量:1417070
I am using a SQLite database in my PhoneGap application. I am able to populate the database, extract the database and also print it using console.log
Here is the code
function extractFromDB(){
var db = window.openDatabase("hospitalsDB", "1.0", "HospitalsDB", false);
db.transaction(queryDB, errorCB);
}
function queryDB(tx) {
tx.executeSql('SELECT * FROM hospitals', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
}
My question is, how do I print this data onto the html page ?
I am using a SQLite database in my PhoneGap application. I am able to populate the database, extract the database and also print it using console.log
Here is the code
function extractFromDB(){
var db = window.openDatabase("hospitalsDB", "1.0", "HospitalsDB", false);
db.transaction(queryDB, errorCB);
}
function queryDB(tx) {
tx.executeSql('SELECT * FROM hospitals', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
}
}
My question is, how do I print this data onto the html page ?
Share Improve this question asked Mar 24, 2013 at 0:03 Ashish AgarwalAshish Agarwal 14.9k31 gold badges88 silver badges126 bronze badges2 Answers
Reset to default 3If i get your question in right way.Assume you have a <div>
in your html page:
var resultDiv = $('#mydiv');
var data = undefined;
for (var i=0; i<len; i++){
data = "Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data;
resultDiv.append(data + "<br>")
This will write all the data into a div in your html page. A simple example smilar to your one: JSFIDDLE
function querySuccess(tx, results) {
<!-- its good programming to check the length of rows returned by sqlite DB.-->
var htmlstring = "";
if (results != null && results.rows != null && results.rows.length > 0) {
for ( var i = 0;i <results.rows.length;i++)
{
htmlstring+= '<div class="ui-grid-a">';
htmlstring += '<div class="ui-block-a">'+results.rows.item(i).id+'</div>';
htmlstring+= '</div>';
}
$("#divholderfordata").empty().append(htmlstring).trigger('create');
}
else
{console.log("no records inserted in DB");}
}
where you can define "div" with id "divholderfordata" in your html code this code will work better as far as "UI" is concerned because it also includes "jquery-mobile" code hope it will help you.
本文标签: javascriptExtracting data from Phonegap39s SQLite databaseStack Overflow
版权声明:本文标题:javascript - Extracting data from Phonegap's SQLite database - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745257536a2650190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论