Hi I am developing a cross-platformm application using cordova. I have a table like this
First I need to get the data and store them in my database.Second when I select a particular customer I need to fetch that particular record and display them in the next page. Here is a code that I have done till now, I have created a database sqlite and a table waitlist,
<script>
document.addEventListener("deviceready", onDeviceReady, false);
var st,et;
var currentRow;
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS waitlist13 (id INTEGER PRIMARY KEY AUTOINCREMENT,name, startdatetime,enddatetime)');
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
function errorCB1(err) {
alert("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
//var db = window.sqlitePlugin.openDatabase({name:"sqlite"});
//db.transaction(queryDB, errorCB);
alert("table waitlist created");
}
function successCB1() {
window.location="waitlist.html";
}
// Cordova is ready
//
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name:"sqlite"});
db.transaction(populateDB, errorCB, successCB);
}
//Insert query
//
function insertDB(tx) {
tx.executeSql('INSERT INTO waitlist13 (name,startdatetime,enddatetime) VALUES ("' +document.getElementById("clienttextbox").value
+'","'+st+'" ,"'+et+'")');
}
function goInsert() {
console.log("start time");
console.log(st);
var currentdate = new Date();
var enddatetime = currentdate.getHours() + ":"+ currentdate.getMinutes() + ":"+currentdate.getSeconds();
et=enddatetime;
console.log(enddatetime);
console.log("end time");
console.log(et);
var db = window.sqlitePlugin.openDatabase({name:"sqlite"});
db.transaction(insertDB, errorCB1, successCB1);
}
</script>
Here I need to change my table structure as,
CREATE TABLE IF NOT EXISTS waitlist13 (id INTEGER PRIMARY KEY AUTOINCREMENT,name, waitingtime,ticketid,ticketname);
Then I need to insert multiple values in insert like this,
tx.executeSql('INSERT INTO waitlist13 (name,waitingtime,ticketid,ticketname) VALUES ("' +document.getElementById("clienttextbox").value
+'","'+st+'" ,"'+et+'")');
How could I get the values from the table I generate and store them on respective column in database with same id? Can someone suggest me a efficient way?Can someone please help me? Thank you in advance...
Aucun commentaire:
Enregistrer un commentaire