Download presentation
Presentation is loading. Please wait.
Published byMarjory O’Neal’ Modified over 7 years ago
1
Creating Databases Local storage. join & split
Classwork: localStorage and join exercise. Homework: [Catch up]. Post proposal for enhanced project. Start studying for midterm.
2
Local storage HTML5 version of cookies
Small file(s) stored as text on local (client) computer Browser specific Only programs (scripts, files) from same domain can use the information. Can be prevented by user.
3
Uses? ?
4
Uses include Our convenience Their convenience
Store ids and passwords. Note: browser may do this independently Customer information, including credit cards Their convenience More than convenience: may be business plan to provide information for others Basic operations
5
Information gathered in cookies, localStorage, beacons, etc. For you, need to put it on (at least) two scales: Convenient to useless? Harmless to creepy?
6
Client side and Server side
Suppose you need processing to go on BEFORE going to the php script In the HTML document, in the head element, define a function that returns true or false. True will cause control to continue to the php script indicated by the action attribute False will NOT continue.
7
HTML document, cont. <script type=“text/javascript”> function preprocess() { return false; … return true; } </script> <body> <form name=“f” action=“process.php” onSubmit=“return process();” > </form> </body>
8
HTML5 JavaScript localStorage
Items stored by name localStorage.setItem(“score”,String(score)); … lastscore = localStorage.getItem(“score”); localStorage.removeItem(“score”);
9
Error checking For localStorage and other things, it makes sense to do error checking, for example, using try { } catch(e) { alert(“problem with local Storage “+e) } Try and catch useful for other situations
10
Example Store date and time Retrieve what is stored (a string) and also displays current date and time Remove stored date and time. What is stored is just the display form of the result of Date().
11
Encoding data What if you have a lot of data….
You can store each thing as its own item OR combine the data into one item Processing an array--encoding Change items to character strings using String Use join to combine into one big string, with a separator of your choosing Decoding Split ????
12
Repeat Warning join is a JavaScript method and also a php method for constructing a string out of elements in an array JOIN is a term that can be used in an SQL SELECT statement to gather records from multiple files.
13
join and split Let class be an array of names: [“Larry”, “Curly”, “Moe] class.join(“+”) produces: “Larry+Curly+Moe” list = class.join(“+”); Then newclass = list.split(“+”); produces the original array.
14
Classwork Assume an array of some number (say 3 to 5) of names.
Write the code to encode this into a single string, separated by commas, and store as localStorage under the name (key, label) “team”. Write the code to retrieve it and print out the names, one to a line.
15
JavaScript Object Notation: json
System of encoding Ordered lists Key-value pairs Supported in JavaScript and php and other languages Can be used to encode (aggregate, combine) information, store, and later decode.
16
Persistent storage So, you have a choice for persistent storage
On the local computer, using HTML5's localStorage or (older) JavaScript cookies OR In a database In a file on the server Other options: session variables: kept on the server. Extra credit opportunity.
17
Book mark project (subject of book chapter in HTML5 and JavaScript Projects) Uses localStorage to store id and password on client computer Uses one-way encryption for client side encoding database to store the sites and the finders included the encrypted digest of the passwords.
18
Client side & server side
<form action=“fix.php” onSubmit=“return prepare();” name=“f”> prepare is a JavaScript function, defined in the <script> element of the html document. The prepare function returns true to send information to the fix script on the server; returns false to NOT go to the server.
19
Oscars application One possible set of tables So what is the ERD?
people Movies Roles Nominations So what is the ERD?
20
My answer 4 tables In most cases, people have only 1 role.
In most cases, awards are for 1 role. Producing is an exception. Some roles are not nominated for anything, hence the 0. 4 tables movies mid name …. people pid name … nominations aid rid category win … roles rid mid pid role (director,actor,etc.)
21
Projects taken Student info Sites, with registration Trivia quiz
(Origami) store
22
Classwork/Homework Practice using localStorage.
Practice with creating tables, writing scripts for input AND display including using SELECT query for specific set of recordsStudy notes and study resources Start studying for midterm (midterm guide, lectures, examples) there will be ER/DFD questions for something… Come to next class with questions. Form team and make proposal for enhanced projects.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.