Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases for Web Applications State capitals quiz Classwork: design a new quiz Homework: Make sure you can upload files and have MySQL database.

Similar presentations


Presentation on theme: "Creating Databases for Web Applications State capitals quiz Classwork: design a new quiz Homework: Make sure you can upload files and have MySQL database."— Presentation transcript:

1 Creating Databases for Web Applications State capitals quiz Classwork: design a new quiz Homework: Make sure you can upload files and have MySQL database. Get a simple quiz working like the state capital quiz. Post unique source on REGULAR expressions.

2 News Added a new General Discussion forum. Use this for questions, comments, news. –the News forum is intended to be just from the teacher! Use the General Discussion forum for 1 of the 2 homework assignments for today!

3 State capital quiz b/statecapquizask.phphttp://newmedia.purchase.edu/~Jeanine/d b/statecapquizask.php Choose what to be asked –Note: how can this be worded better???? Ask Check the answer –Give chance to try again or –Go back to get new question

4 State capitals quiz Implementation: three php files. Two of the php files call themselves and include the other file. –statecapitals.php This file is include[d] in the others. It sets up 2 parallel arrays holding the names of the states and the capital cities. –statecapquizask.php This is a multi-purpose file. –statecapquizcheck.php This is also a multi-purpose file. Checks answer. Allows for another guess or goes back to statecapquizask.php

5 State capitals storyboard statecapquiz.php statecapquizcheck.php Include file: statecapitals.php

6 Programming practices Parallel structures, in this case the array of states corresponding to the array of capitals, is a common programming device. Think of it as an alternative to a database or xml for simple cases. Self-referencing of php scripts is a common practice (mentioned last class) –benefits: reduces number of files. Information in one place –negatives: the one file is more complex

7 Materials Go to [our] moodle site: –sign in and go to the class. –go to Code Examples –click on StateCapitalQuiz NOTE: using View source on the browser does not show the whole php file!

8 statecapitals.php

9 statecapquizask.php State capitals quiz: check State Capital Quiz

10 if ($which=='state') { $state = $states[$choice]; print("What is the capital of $state? "); print(" \n"); print(" "); print(" \n"); }

11 else { $capital = $capitals[$choice]; print("$capital is the capital of which state? "); print(" \n"); print(" "); print(" \n"); }

12 else { print("Choose form of question: do you want to be given the state or the capital? "); print(" \n"); print("Ask State"); print(" Capital\n"); print(" \n"); print(" "); print(" "); } ?>

13 statecapquizcheck.php State capitals quiz: check

14 if ($which=='state') { if ($capital == $correctcapital) { print("Correct! $correctcapital is the capital of $correctstate!"); print(" Play again "); }

15 else { print("WRONG! \n"); print(" New turn \n"); print("OR try again: What is the capital of $correctstate? "); print(" \n"); print(" "); print(" \n"); } }

16 else { if ($state == $correctstate) { print("Correct! The capital of $correctstate is $correctcapital!"); $saywhich='false'; print(" Play again "); }

17 else { print("WRONG! \n"); print(" New turn \n"); print("OR try again: $correctcapital is the capital of what state? "); print(" \n"); print(" "); print(" \n"); } } ?>

18 else { $capital = $capitals[$choice]; print("$capital is the capital of which state? "); print(" \n"); print(" "); print(" \n"); } }

19 else { print("Choose form of question: do you want to be given the state or the capital? "); print(" \n"); print("Ask State"); print(" Capital\n"); print(" \n"); print(" "); print(" "); } ?>

20 Reprise if statements within if statements php produces the appropriate html, including the form element The php is printing (producing) html. It is not operating the quiz! There are ways to enhance this program –perhaps limit the number of re-tries THIS WILL BE A HOMEWORK ASSIGNMENT!

21 Classwork (teams) Design simple quiz like the state capital quiz, using parallel arrays for questions and answers –Ideas? OR make significant enhancement to my quiz, like adding scoring, limiting re-tries OR some other quiz!

22 Homework Get your quiz working. Post link in posting to the General Discussion Forum. Research and post unique source on Regular expressions on the Links and sources forum. We use regular expressions to validate input and extract information from input.


Download ppt "Creating Databases for Web Applications State capitals quiz Classwork: design a new quiz Homework: Make sure you can upload files and have MySQL database."

Similar presentations


Ads by Google