Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.

Slides:



Advertisements
Similar presentations
ProgressBook User Start-Up
Advertisements

Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple.
Chapter 4 Joining Multiple Tables
Database Design Week 10.
CC SQL Utilities.
1099 Pro, Inc. – Software for Pro Enterprise Edition Features.
Introduction to Structured Query Language (SQL)
1 Creating and Tweaking Data HRP223 – 2010 October 24, 2011 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Introduction to Structured Query Language (SQL)
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Introduction to Structured Query Language (SQL)
Microsoft Access 2010 Chapter 7 Using SQL.
MS Access: Database Concepts Instructor: Vicki Weidler.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
An Introduction to Textual Programming
Creating databases for web applications
Creating databases for web applications Walk before run? Songs with features example. Retrieve information from database. Recordsets. Arrays. Loops. Homework:
Creating Databases for Web Applications SQL Select extras Listing [names of] tables generalized display of recordset simple password handling php and other.
Creating databases for web applications SQL. Systems design. ER diagrams. Data flow diagrams. Storyboards. Homework: Plan database and applications for.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
Microsoft Access Get a green book. Page AC 2 Define Access Define database.
PHP meets MySQL.
 Continue queries ◦ You completed two tutorials with step-by-step instructions for creating queries in MS Access. ◦ Now must apply knowledge and skills.
Analyzing Data For Effective Decision Making Chapter 3.
Programming using C# Joins SQL Injection Stored Procedures
Creating Databases More SQL. Design. Original Project Assignment Homework: Post proposal. Continue with planning.
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
Creating databases for web applications Database datatypes. Creating database Homework: Create tables in database. Add records to database.
MathXL ® for School Teacher Training Series Creating Homework Assignments.
Creating databases for Web Applications php basics. ing. phpMyAdmin to set up MySQL. Homework: Use phpMyAdmin. Make posting with [unique] source on.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Creating Databases for web applications [Complete presentations] More SQL Class time: discuss final projects. Do posting if you have not done it.
Creating databases for web applications Library. New example: student database. Homework: Complete class example. Catch up on source postings. Do creation.
I want to do SQL, I start as if I am doing a regular query.
When I want to work with SQL, I start off as if I am doing a regular query.
Grade Book Database Presentation Jeanne Winstead CINS 137.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
XP New Perspectives on Microsoft Access 2002 Tutorial 31 Microsoft Access 2002 Tutorial 3 – Querying a Database.
Creating databases for web applications Report on using sources, getting examples working. Retrieve information from database. Recordsets. Arrays. Loops.
Creating Databases for Web applications SQL. XML. Linked Lists. NoSQL. Homework: Keep working on projects. Post constructive feedback on other projects.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
Creating Databases for Web Applications State capitals quiz: demonstrates parallel structures AND multi-purpose php files Classwork: design a new quiz.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Creating Databases for Web applications Making a table of table information. Reprise on database design. SQL. Classwork/Homework: Projects! Postings.
Decision Analysis Fall Term 2015 Marymount University School of Business Administration Professor Suydam Week 10 Access Basics – Tutorial B; Introduction.
DAY 20: ACCESS CHAPTERS 5, 6, 7 Larry Reaves October 28,
Confirm teams. Review of diagrams. SELECT problems.
Creating Databases Local storage. join & split
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Creating databases for web applications
Creating Databases for Web Applications
Creating databases for web applications
Access Maintaining and Querying a Database
What is Google Classroom?
Creating Databases SELECT. UPDATE. Demonstrate projects. Do not track.
Tutorial 3 – Querying a Database
Lab 2 HRP223 – 2010 October 18, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected.
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Creating Databases SELECT. UPDATE. Demonstrate projects. Classwork / Homework: Prepare to choose teams & projects.

Warning Changes in php from last time. –THIS IS INEVITABLE and is mainly a good thing. I think I made required changes, but only did modest testing. –AND I did all the testing. Always involve other people to do testing!

SELECT … what if you want only DISTINCT values? For example, the trivia quiz starts with a form to choose the category. People (site administrators) adding questions can put in any category. meyer/quiz/choosecategory.phphttp://socialsoftware.purchase.edu/jeanine. meyer/quiz/choosecategory.php

from php code choosecategory.php Welcome to the Quiz Sign in and select a category for your question Name <input type=text name='player' size=30 <?php … $query="SELECT DISTINCT category FROM questions"; $categories = mysqli_query($link,$query); while ($row=mysqli_fetch_array($categories)) { $cat=$row['category']; print (" $cat \n"); }

SQL join SELECT statement against a table made up by JOINing tables together on identical fields. Different types of JOIN: –JOIN (same as INNER JOIN) –LEFT JOIN –RIGHT JOIN –FULL JOIN

LEFT, RIGHT, FULL JOINs These provide ways to pick up missing records. CHECK OUT THE w3schools and other tutorials! Will show example from the quiz show –Task: find questions that player has NOT answered correctly and has NOT been asked that day.

Two steps Create a temporary table of all the questions asked a particular player and answered correctly OR asked today. –need to specify the contents of the table. In this case, one field of INT datatype If there have been past questions, do a SELECT using LEFT JOIN to extract any question NOT present in the past array. Otherwise, do a simple SELECT

$query="CREATE temporary TABLE past (item_id INT)"; $query.= " SELECT question_id FROM history WHERE (player_id='".$player_id; $query.= "' AND (whenplayed='".$today."' OR correct))"; $result=mysqli_query($link,$query); $query="SELECT * FROM past"; $result = mysqli_query($link,$query); $Num_past = mysqli_num_rows($result); 1st step: create temporary table, past

2 nd step if ($Num_past>0) { $sel = "SELECT questions.question_id, question, answerpattern, value from questions"; $sel =$sel. " LEFT JOIN past ON questions.question_id = past.question_id WHERE "; $sel = $sel. " category='". $pickedcategory. "' AND past.question_id IS NULL"; } else { $sel="SELECT question_id, question, answerpattern, value from questions "; $sel= $sel. " WHERE category= '". $pickedcategory. "'"; }

SELECT Conditions WHERE –Sets condition on individual records with a JOIN –the ON specifying what field to do the JOIN on, generally a foreign key equal to a primary key After aggregating using GROUP – HAVING sets a condition on grouped data

Conditions Remember: the single equal sign is the operator for equality! Other comparisons: >, =, <= LOGIC: AND, OR, NOT REGEX for regular expressions LIKE: another way to specify a pattern

Conditions Can select using set of values SELECT * FROM questions WHERE category IN (‘trivia’,’misc’,’silly’) See also BETWEEN

Recall 4 tables movies mid mname mdate people pid pname … roles rid mid pid role (director,actor,etc.) nominations aid rid category win … In most cases, people have only 1 role. Affleck is an exception. In most cases, awards are for 1 role. Producing is an exception. Some roles are not nominated for anything, hence the 0. 0

Tasks List all movies by name, ordered by date –SELECT mname, mdate FROM movies ORDER BY mdate List all people by name with roles in a given movie, named $moviename (this is mixture of php and straight SQL) –SELECT p.pname,m.mname,r.role FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid WHERE m.mname='$moviename'

next task: reuse JOIN clauses List all directors (by name), with movie (by name) ordered by movie name –SELECT p.pname,m.mname FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid WHERE r.role='Director' ORDER BY m.mname

List all movies by name in which someone was nominated for Best Lead Actor –SELECT m.mname FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid JOIN nominations as n ON n.rid=r.rid WHERE n.award='Best Lead Actor'

next task, again reuse JOIN clauses plus start of WHERE List all movies by name in which someone was nominated for an acting category. Count number. –Best Lead Actor, Best Lead Actress, Best Supporting Actor, Best Supporting Actress –SELECT m.mname, count(*) FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid JOIN nominations as n ON n.rid=r.rid WHERE n.award IN ('Best Lead Actor, Best Lead Actress, Best Supporting Actor, Best Supporting Actress) ORDER BY m.mname GROUP BY m.mname

More List movie name, person name, nominated award ordered by movie name –SELECT m.mname, p.pname, n.award FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid JOIN nominations as n ON n.rid=r.rid ORDER BY m.mname

Next List winners: movie name, person name, award –SELECT m.mname, p.pname, n.award FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid JOIN nominations as n ON n.rid=r.rid ORDER BY m.mname WHERE n.win='true'

List movie name, number of people nominated, ordered from high to low –SELECT m.mname, count(*) FROM movies as m JOIN roles as r ON m.mid = r.mid JOIN people as p ON p.pid = r.rid JOIN nominations as n ON n.rid=r.rid ORDER BY m.mname GROUP BY m.mname –EXTRA CREDIT: figure out how not to count multiples for awards that have multiples (such as producer, technical awards)

Research Some questions require consideration of absent records –What movies were nominated (had people nominated) for Best Movie but not Best Director –? Look up and study examples of LEFT JOINS

UPDATE Can update a single record or a set of records. UPDATE questions SET text = ‘$ntext’ WHERE ques_id=‘$qid’ –Assumes table names questions with fields text and ques_id and php variables $ntext and $qid set previously

UPDATE Raise all the prices 10% –UPDATE products SET price=1.10*price Raise the prices that are over 100 by 5% –UPDATE products SET price=1.05*price WHERE price > 100

Projects Recall Geolocation / Google maps . meyer/ ing/geolocationkm .html meyer/ ing/geolocationkm .html Quizhttp://faculty.purchase.edu/jeanine.me yer/html5/mapmediaquiz.htmlhttp://faculty.purchase.edu/jeanine.me yer/html5/mapmediaquiz.html Does not use database. Enhancement is to add database for locations

Projects Bookmarks, with password system for finders – yer/research/addsite.htmlhttp://socialsoftware.purchase.edu/jeanine.me yer/research/addsite.html – yer/research/showsitesbycategory1.phphttp://socialsoftware.purchase.edu/jeanine.me yer/research/showsitesbycategory1.php

Projects Student departments meyer/studentexample/showstudents.php meyer/studentexample/showdepartments. php meyer/studentexample/enterstudent.html meyer/studentexample/showstudents.php meyer/studentexample/showdepartments. php meyer/studentexample/enterstudent.html

Projects Trivia quiz meyer/quiz/choosecategory.php meyer/quiz/inputquestions.php meyer/quiz/choosecategory.php meyer/quiz/inputquestions.php –edit feature? –change scoring? –improve interface?

Projects Origami store meyer/orders/orderproduct.php meyer/orders/inputproducts.php need file upload to upload pictures meyer/orders/orderproduct.php meyer/orders/inputproducts.php –general improvement –scale up

Projects Songs and features in songs. Find similar songs meyer/example/findothers1.php meyer/example/addsong.html meyer/example/addfeature.html meyer/example/addfeaturestosong1.php meyer/example/findothers1.php meyer/example/addsong.html meyer/example/addfeature.html meyer/example/addfeaturestosong1.php

Stories meyer/stories/tellStory.phphttp://socialsoftware.purchase.edu/jeanine. meyer/stories/tellStory.php meyer/stories/enterscene.htmlhttp://socialsoftware.purchase.edu/jeanine. meyer/stories/enterscene.html meyer/stories/addscene.phphttp://socialsoftware.purchase.edu/jeanine. meyer/stories/addscene.php meyer/stories/showAllScenesforediting.ph phttp://socialsoftware.purchase.edu/jeanine. meyer/stories/showAllScenesforediting.ph p

Citations meyer/citations/drawlinksAsArrows.phphttp://socialsoftware.purchase.edu/jeanine. meyer/citations/drawlinksAsArrows.php meyer/citations/inputjournals.phphttp://socialsoftware.purchase.edu/jeanine. meyer/citations/inputjournals.php meyer/citations/inputarticles.phphttp://socialsoftware.purchase.edu/jeanine. meyer/citations/inputarticles.php meyer/citations/addlink1.phphttp://socialsoftware.purchase.edu/jeanine. meyer/citations/addlink1.php

Assignment Team project to present and Enhance one of these projects There will be an assignment to build database project totally on your own

Projects student database trivia quiz book marks songs origami store Stories Google maps media portal (or quiz) –Note: this does NOT have a database at all! So obvious enhancement is to make use of database, possibly with table for player or ??? Late addition: citations (needs updating)

Preview (after midterm) Self assign or I assign teams (4-5) Teams will pick projects –resolve conflicts

Homework Prepare to form teams AND choose application. Working with existing code is…always a challenge but more common than starting from nothing.