03-05-2013 12:46 PM
Having (almost) gotten my head round implementing SQLite in my HTML5 app, I was wondering about how I would go about entering data from more than one webpage into the same line of a given database.
Part of the application includes Character Creation forms (spread across three Web pages), and this is where I've started running into problems...
I think I have the right code to set up the database and insert the table into it, but when it comes to adding information into a few columns from one line (or updating said data), I haven't a clue...
Will I have to define a custom function to update just the fields on each page? How would I even do that? ...and how can I check I'm inputting (?) the data into the right line of the table?
Thanks in advance,
03-05-2013 01:43 PM
Best practice would be to consolidate all the data and write it to the DB at the same time. You want to keep DB transactions to a minimum as they're expensive.
If you don't want to do that, then you at least need a common, unique element from the database to be available on each page.
Lets say you had 2 pages (to simplify things).
Page one had you entering the following data fields (name, strength)
Page two had you entering the following data fields (name, intellect)
Name would be your common, unique identifier use to reference the proper row in the database.
After checking to ensure that the name doesn't exist (and using an INSERT statemebt) your 2 SQL statements would resemble:
"UPDATE tablename SET strength = ? WHERE name = ?"
"UPDATE tablename SET intellect = ? WHERE name = ?"
03-05-2013 01:58 PM
Thanks for your quick reply
If it's better to consolidate the data before writing it, how would I go about this? This is my first app, so I would prefer to learn to do things correctly first time round. Would you be kind enough to provide a code example, please?
Thanks in advance