I can place database results on-screen using PHP and MySQL, but I’m at a loss figuring out how to do the same when using Javascript.
On this page, we have instructions on using a database: SQLResultSetList
http://docs.phonegap.com/en/2.0.0/cordova_storage_storage.md.html#Storage
However, in this example, the output goes to the console:
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function queryDB(tx) {
* * tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
console.log("Returned rows = " + results.rows.length);
// this will be true since it was a select statement and so rowsAffected was 0
if (!resultSet.rowsAffected) {
* console.log('No rows affected!');
* return false;
}
// for an insert statement, this property will return the ID of the last inserted row
console.log("Last inserted row ID = " + results.insertId);
}
How do I use Javascript get the output to go to between <div><p></p></div> tags so I could format the text for each column in the rows? For instance, in the format of the following, with the id value in one div and the data value in the second div, continuing until all the data has been displayed:
<div class=a><p>Title: 1 </p></div>
<div class=a><p>Name: First row</p></div>
This does not take place on a server, but in a mobile device, so PHP is not used.