Ok i have this function. what it should be doing it looking for pid in sql and if found skip the function and move on, but I dont think my if statment is working right.
function getblogpost(div) {
var date = $(div).find('.time').text();
var user = $(div).find('.user').text();
var title = $(div).find('.title').text();
var textbody = $(div).find('.bodytext').text();
var postid = $(div).find('.pid').text();
var q = tx.executeSql("SELECT * FROM blogpost WHERE postid=" + postid,
[], function(transaction, result) {
var sqlpostid = result.rows.item(i)['postid'];
}, null);
if(result == NULL) {
return;
}
else {
dbsql.transaction(
function(transaction) {
transaction.executeSql(
'INSERT INTO blogpost (postid, date, user, title, textbody)
VALUES (?, ?, ?, ?, ?);',
[postid, date, user, title, textbody],
function() { },
errorHandler
);
}
);
return false;
}
}
Should this not work?
Thanks
Edit: what about this.
function getblogpost(div) {
var postid = $(div).find('.pid').text();
var q = tx.executeSql("SELECT * FROM blogpost WHERE postid=" + postid, [], function(transaction));
if(!q) {
return false;
}
var date = $(div).find('.time').text();
var user = $(div).find('.user').text();
var title = $(div).find('.title').text();
var textbody = $(div).find('.bodytext').text();
dbsql.transaction(
function(transaction) {
transaction.executeSql(
'INSERT INTO blogpost (postid, date, user, title, textbody) VALUES (?, ?, ?, ?, ?);',
[postid, date, user, title, textbody],
function() { },
errorHandler
);
}
);
return false;
}
What i'm trying to do here is find out if postid is in the database and if so skip the function and return.