I have thie function and need to know if im going about it the right way.
What it does it looks up the last entry into the sql called "LastID" and if the return is the same as "postid" it returns false.
function LastPost(div)
should look up the last post.
and UpDateSQL(div,LastID)
checks the if condition else inputs into the database.
What im trying to do is stop repeat posts been inputted into the local sql.
$('.main').each(function(){
LastPost(this);
});
function LastPost(div) {
dbsql.transaction(function(transaction) {
transaction.executeSql("SELECT * FROM blogpost LIMIT 1", [],function(transaction, result) {
var LastID = result.rows.item(i)['postid'];
var LastDate = result.rows.item(i)['date'];
UpDateSQL(div,LastID);
}, null);
});
}
function UpDateSQL(div,LastID) {
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();
if(LastID == postid){
return false;
}
dbsql.transaction(
function(transaction) {
transaction.executeSql(
'INSERT INTO blogpost (postid, date, user, title, textbody) VALUES (?, ?, ?, ?, ?);',
[postid, date, user, title, textbody],
function(){
},
errorHandler
);
}
);
return false;
}