Mapping from a database Peterson. Linux PHP and MySQL were largely developed under Linux – open source operating system based on UNIX Linus Torvalds –

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Relational Database Systems Higher Information Systems Advanced Implementation in MySQL/PHP.
Object Relational Model Spatial Queries. Query Model Spatial Layer Data Table where coordinates are stored Primary Filter Spatial Index Index retrieves.
Keys, Referential Integrity and PHP One to Many on the Web.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)MySQL Recap.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
Lines and Polygons Peterson. Simple Line function initialize() { var myLatLng = new google.maps.LatLng(5, -170); var myOptions = { zoom: 2, center: myLatLng,
TECNOLOGIAS DE ARMAZENAMENTO DE INFORMAÇÃO ESPACIAL.
Databases, MySQL, and PHP Peterson. The Social Network The first thing we're gonna need is a lot of pictures. Unfortunately, Harvard doesn't keep a public.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
MySql In Action Step by step method to create your own database.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
Session 5: Working with MySQL iNET Academy Open Source Web Development.
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
Internet and Web Application Development Revision.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Web Application Development. Define ER model in QSEE Generate SQL Create Database mySQL Write Script to use TableEditor class Process to create A simple.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Final Exam Guide PHP NOTE: PHP CODE WILL BE BLUE, HTML IS BLACK EXAMPLE
Introduction to MySQL Lab no. 10 Advance Database Management System.
18 Mapping from a database Mapping in the Cloud Peterson.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
PHP Part 2.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Database Fred Durao What is a database? A database is any organized collection of data. Some examples of databases you may encounter in.
PHP with MySQL 1.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
Web Programming Language Week 7 Dr. Ken Cosh PHP and storage.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Relational Schema and SQL Queries James Wang.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
CHAPTER 10 PHP MySQL Database
>> PHP: MySQL & CRUD. R ecall Database Tables Records is composed of Operations (CRUD) Create Retrieve Update Delete DBMS Access Control MySQL phpMyAdmin.
MySQL MySQL and PHP – interacting with a database.
Class11 Introduction to relational databases and MySQL MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Google Maps API. Contents: 1. Google Maps API Key 2. Create a Basic Google Map 3. Google Maps Overlays 4. Google Maps Events 5. Google Maps Controls 6.
Creating Database Objects
Introduction to Web programming
Database application MySQL Database and PhpMyAdmin
Principles of Software Development
Website Development Basics with PHP MySQL
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 6, 2016
Web Maps with Leaflet GEOG 319/658 November 24, 2014.
Creating Database Objects
SQL (Structured Query Language)
Presentation transcript:

Mapping from a database Peterson

Linux PHP and MySQL were largely developed under Linux – open source operating system based on UNIX Linus Torvalds – – “Hello everybody out there! I'm doing a (free) operating system … (just a hobby, won't be big and professional) for 386(486) AT clones. This has been brewing since april, and is starting to get ready.I'd like any feedback.”

PHP and MySQL Most Linux installation procedures include the option of installing PHP and MySQL. Administration of online databases is done through phpMyAdmin – Available through the cPanel Purpose of exercises: – Develop familiarity with PHP – Input and query MySQL tables

PHP Example 1

PHP example 2

PHP example 3

PHP example 4

PHP Example 5

PHP Example 6

PHP Example 7

PHP Example 8

cPanel

MySQL is used to define new tables

SQL

Browse

Structure

SQL

Search

mysql_connect.php

All Capitals

//connection to database and querying <?php include 'mysql_connect.php'; $table = "us_capitals"; $sql = "SELECT name, usstate, population, Y(location), X(location) FROM $table"; $res = mysql_query($sql); if($res){ $num = mysql_num_rows($res); while($row = mysql_fetch_array($res)){ // contents one row of database $lat = $row['X(location)']; $lon = $row['Y(location)']; $name = $row['name']; $state = $row['usstate']; $pop = $row['population']; // create marker echo 'var myLatlng = new google.maps.LatLng('.$lat.','.$lon.');'; echo 'var marker = new google.maps.Marker({position: myLatlng, map: map, title: "'.$name.', Population: '.$pop.'", icon: image, shadow: shadow});'; // info message will be attached echo 'attachMessage(marker, "'.$name.'", "'.$state.'", "'.$pop.'");'; } } else echo "alert('SQL-Error getting data from database...')"; mysql_close($conn); ?>

North of Omaha / less than 500,000

//connection to database and querying <?php include 'mysql_connect.php'; $table = "us_capitals"; $sql = "SELECT name, usstate, population, Y(location), X(location) FROM $table WHERE X(location) > AND population < "; $res = mysql_query($sql);

Select within box

<?php //define coordinates and draw rectangle to map include 'mysql_connect.php'; $table = "us_capitals"; $sql =" SELECT name, Y(location), X(location), usstate, population FROM us_capitals WHERE Intersects( location, GeomFromText( 'POLYGON((40 -96, , , , ))' ) ) ";

DROP TABLE IF EXISTS cities; create table cities ( city VARCHAR(30), location GEOMETRY NOT NULL, SPATIAL INDEX(location), PRIMARY KEY (city) ); INSERT INTO cities (city, location) VALUES ("Omaha", GeomFromText('POINT( )')); INSERT INTO cities (city, location) VALUES ("Atlanta", GeomFromText('POINT( )')); INSERT INTO cities (city, location) VALUES ("Lincoln", GeomFromText('POINT( )')); DROP TABLE IF EXISTS dl_airports; create table dl_airports ( city VARCHAR(30), airport VARCHAR(30), code VARCHAR(3), FOREIGN KEY (city) REFERENCES cities(city), PRIMARY KEY (code) ); INSERT INTO dl_airports (city, airport, code) VALUES ("Omaha","Omaha Eppley Airfield", "OMA"); INSERT INTO dl_airports (city, airport, code) VALUES ("Atlanta","Hartsfield-Jackson International Airport", "ATL"); INSERT INTO dl_airports (city, airport, code) VALUES ("Lincoln","Municipal Airport", "LNK"); DROP TABLE IF EXISTS dl_routes; create table dl_routes ( airportCode VARCHAR(3), destinationCode VARCHAR(3), FOREIGN KEY (airportCode) references dl_airports(code), FOREIGN KEY (destinationCode) references dl_airports(code) ); INSERT INTO dl_routes (airportCode, destinationCode) VALUES ("OMA","ATL"); INSERT INTO dl_routes (airportCode, destinationCode) VALUES ("OMA","DET"); INSERT INTO dl_routes (airportCode, destinationCode) VALUES ("OMA","MEM"); Part of the SQL code for entering three tables that provide city location, airport information, and airline connections.

Flight Routes

<?php include 'mysql_connect.php'; $sql = "SELECT cDep.city AS departure, X( cDep.location ) AS latDep, Y( cDep.location ) AS lngDep, cDst.city AS destination, X( cDst.location ) AS latDest, Y( cDst.location ) AS lngDest FROM ((( dl_routes AS rt INNER JOIN dl_airports AS ap1 ON rt.airportcode = ap1.code ) INNER JOIN dl_airports AS ap2 ON rt.destinationcode = ap2.code ) INNER JOIN cities AS cDep ON cDep.city = ap1.city_name ) INNER JOIN cities AS cDst ON cDst.city = ap2.city_name"; $res = mysql_query($sql); if($res){ $num = mysql_num_rows($res); while($row = mysql_fetch_array($res)){ echo "var flightPlanCoordinates = [ new google.maps.LatLng(".$row['latDep'].", ".$row['lngDep']."), new google.maps.LatLng(".$row['latDest'].", ".$row['lngDest'].") ]; flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: \"#FF0000\", strokeOpacity: 0.8, geodesic: true, strokeWeight: 1 }); flightPath.setMap(map);"; } } else echo "alert('SQL-Error getting data from database...')"; mysql_close($conn); ?>

Selected routes

$sql = "SELECT cDep.city AS departure, X( cDep.location ) AS latDep, Y( cDep.location ) AS lngDep, cDst.city AS destination, X( cDst.location ) AS latDest, Y( cDst.location ) AS lngDest FROM ( ( dl_routes AS rt INNER JOIN dl_airports AS ap1 ON rt.airportcode = ap1.code ) INNER JOIN dl_airports AS ap2 ON rt.destinationcode = ap2.code ) INNER JOIN cities AS cDep ON cDep.city = ap1.city_name ) INNER JOIN cities AS cDst ON cDst.city = ap2.city_name WHERE cDep.city = 'Omaha'"; $res = mysql_query($sql);

create table ne_counties ( strokecolor VARCHAR(7), strokewidth INT(5), strokeopacity FLOAT(5), fillcolor VARCHAR(7), fillopacity FLOAT(5), popdata INT(15), name VARCHAR(30), geom GEOMETRY NOT NULL, SPATIAL INDEX(geom) ); INSERT INTO ne_counties (strokecolor, strokewidth, strokeopacity, fillcolor, fillopacity, popdata, name, geom) VALUES ("#008800",1,1.0,"#FFCC00", ,33185,"county", GeomFromText('POLYGON(( , , , , , , , , , , , , ))')); INSERT INTO ne_counties (strokecolor, strokewidth, strokeopacity, fillcolor, fillopacity, popdata, name, geom) VALUES ("#008800",1,1.0,"#FFCC00", ,6931,"county", GeomFromText('POLYGON(( , , , , , , , , , , , , ))')); MySQL commands, attributes, and coordinates for placing two county polygons for Nebraska into a MySQL database.

Nebraska county polygons

//connection to database and querying <?php include 'mysql_connect.php'; $sql = "SELECT popdata, AsText(ExteriorRing(geom)) AS linestring FROM ne_counties;"; $res = mysql_query($sql); // first statement -> get all polygons if($res){ // loop through all polygons while($row = mysql_fetch_array($res)){ $linestring = $row['linestring']; //points of current county polygon $pop = $row['popdata']; //population of current county //linestring includes all points of current polygon LINESTRING( , ) //delete not needed characters $clearedLS = str_replace(array("LINESTRING(", ",", ")"),array(""," ",""),$linestring); //parse the string in PHP and store coordinates in array $coordinates = explode(" ", $clearedLS); //read coordinates from array by pair

//and finally create javascript GM latitude/longitude objects for polygons echo "var pts = new Array();"; $j=0; for ($i =0; $i<count($coordinates); $i=$i+2){ echo "pts[".$j."] = new google.maps.LatLng(".$coordinates[$i].",".$coordinates[$i+1].");"; $j++; } echo "polygon = new google.maps.Polygon({ paths: pts, strokeColor: '#0000FF', strokeOpacity: 1.0, strokeWeight: 0.5, fillColor: '#0000FF', fillOpacity: 0.4 });"; echo "polygon.setMap(map);"; } } else echo "alert('SQL-Error getting data from database...')"; mysql_close($conn); ?>

Nebraska county population

// Find the min and max population values for the 93 counties after doing a non-linear transformation using the log function var min= ; var max= ; for (var i = 0; i < 93; i++) { // Log the data to deal with counties with large populations popdata[i] = Math.log(popdata[i]) if (popdata[i] < min) { min=popdata[i] } if (popdata[i] > max) { max=popdata[i] } } // Find the range and compute the opacities for each polygon var range = max-min // compute an opacity as a range of the data values opacities = new Array () for (var i = 0; i < 93; i++) { opacities[i] = 1-((max - popdata[i]) / range) }

Counties with less than 50,000 $sql = "SELECT popdata, AsText(ExteriorRing(geom)) AS linestring FROM ne_counties WHERE popdata < 50000;"; $res = mysql_query($sql);

<?php include 'mysql_connect.php'; $sql = "SELECT popdata, AsText( ExteriorRing( geom ) ) AS geom FROM ne_counties WHERE Intersects( GeomFromText( 'POINT( )' ), geom ) OR Intersects( GeomFromText( 'POINT( )' ), geom ) OR Intersects( GeomFromText( 'POINT( )' ), geom ) "; $res = mysql_query($sql);