我只希望在“ VacantSpaces”不为0的情况下执行更新查询。换句话说,一旦不再有特定事件的空间,“ VacantSpaces”将为0,因此该想法是用户不应加入,号码将不会为-1,-2等。
但是我不太确定如何去做。
JavaScript函数:
function updateEvent(title) {
db = window.openDatabase("SoccerEarth", "2.0", "SoccerEarthDB", 2 * 1024 * 1024);
db.transaction(function(tx) {
tx.executeSql("Update EventSoccer SET VacantSpaces = VacantSpaces -1, NoPeople = NoPeople + 1
WHERE Title = '" + title + "'",
[],
successJoin,
errorCB
);
});
function successJoin() {
navigator.notification.alert("You have joined the event!",
null,
"Information", "ok");
$( ":mobile-pagecontainer" ).pagecontainer( "change", "#page4" );
}
}
最佳答案
您是否尝试过执行以下查询:
tx.executeSql("Update EventSoccer SET VacantSpaces = VacantSpaces -1, NoPeople = NoPeople + 1
WHERE Title = '" + title + "' AND VacantSpaces > 0",
[],
successJoin,
errorCB
);
注意:请使用传递给函数的空数组
[]
作为第二个参数来清理输入。