|
 |
มีคำถามเกี่ยวกับ openDatabase(); ใช้งานยังไงแล้วมันเก็บค่าไว้ที่ไหนยังไง |
|
 |
|
|
 |
 |
|
มีคำถามเกี่ยวกับ openDatabase(); ใช้งานยังไงแล้วมันเก็บค่าไว้ที่ไหนยังไงเหรอครับเช่น
เวลารันสามารถaddค่าลบค่าจัดการต่างๆได้แต่อยากทราบว่าขอมูลที่เราเพิ่มลงไปไปอยู่ที่ไหน
Code (JavaScript)
var results = document.getElementById('results');
var id = document.getElementById('id');
var firstName = document.getElementById('firstName');
var lastName = document.getElementById('lastName');
var phone = document.getElementById('phone');
var createStatement = "CREATE TABLE IF NOT EXISTS Contacts (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName TEXT, phone TEXT)";
var selectAllStatement = "SELECT * FROM Contacts";
var insertStatement = "INSERT INTO Contacts (firstName, lastName, phone) VALUES (?, ?, ?)";
var updateStatement = "UPDATE Contacts SET firstName = ?, lastName = ?, phone = ? WHERE id = ?";
var deleteStatement = "DELETE FROM Contacts WHERE id=?";
var dropStatement = "DROP TABLE Contacts";
var db = openDatabase("AddressBook", "1.0", "Address Book", 200000);
var dataset;
createTable();
function onError(tx, error) {
alert(error.message);
}
function showRecords() {
results.innerHTML = '';
db.transaction(function(tx) {
tx.executeSql(selectAllStatement, [], function(tx, result) {
dataset = result.rows;
for (var i = 0, item = null; i < dataset.length; i++) {
item = dataset.item(i);
results.innerHTML +=
'<li>' + item['lastName'] + ' , ' + item['firstName'] + ' <a href="#" onclick="loadRecord('+i+')">edit</a> ' +
'<a href="#" onclick="deleteRecord('+item['id']+')">delete</a></li>';
}
});
});
}
function createTable() {
db.transaction(function(tx) {
tx.executeSql(createStatement, [], showRecords, onError);
});
}
function insertRecord() {
db.transaction(function(tx) {
tx.executeSql(insertStatement, [firstName.value, lastName.value, phone.value], loadAndReset, onError);
});
}
function loadRecord(i) {
var item = dataset.item(i);
firstName.value = item['firstName'];
lastName.value = item['lastName'];
phone.value = item['phone'];
id.value = item['id'];
}
function updateRecord() {
db.transaction(function(tx) {
tx.executeSql(updateStatement, [firstName.value, lastName.value, phone.value, id.value], loadAndReset, onError);
});
}
function deleteRecord(id) {
db.transaction(function(tx) {
tx.executeSql(deleteStatement, [id], showRecords, onError);
});
resetForm();
}
function dropTable() {
db.transaction(function(tx) {
tx.executeSql(dropStatement, [], showRecords, onError);
});
resetForm();
}
function loadAndReset(){
resetForm();
showRecords();
}
function resetForm(){
firstName.value = '';
lastName.value = '';
phone.value = '';
id.value = '';
}
ปล.ขอบคุณทุกท่านที่เข้ามาช่วยตอบคำถาม
Tag : HTML/CSS, JavaScript, jQuery
|
|
 |
 |
 |
 |
Date :
2013-02-05 16:17:27 |
By :
ninjadark |
View :
970 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ๊ว อันนี้เขียนร่วมกับอะไรครับ แปลก ๆ
|
 |
 |
 |
 |
Date :
2013-02-05 17:55:21 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|