PHP Sample Application Simple graphics and database.

Slides:



Advertisements
Similar presentations
Introduction to Web Design Lecture number:. Todays Aim: Introduction to Web-designing and how its done. Modelling websites in HTML.
Advertisements

Support.ebsco.com EBSCOhost Mobile Tutorial. Welcome to the EBSCOhost Mobile tutorial, a guide to the most popular EBSCOhost features available for use.
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Process Monitoring is only the first step in improving process efficiency.
Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013.
TRACK 2™ Version 5 The ultimate process management software.
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
Higher-level PHP constructs for manipulating image files (contd.)
HTML Lesson 2 TBE 540 Farah Fisher. Prerequisites Access web pages and navigate Use search engines to locate specific information Download graphics from.
Higher-level PHP constructs for manipulating image files.
Sara SartoliAkbar Siami Namin NSF-SFS workshop July 14-18, 2014.
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
Pasewark & Pasewark 1 Access Lesson 4 Creating and Modifying Forms Microsoft Office 2007: Introductory.
Access Lesson 4 Creating and Modifying Forms
1 Access Lesson 5 Creating and Modifying Reports Microsoft Office 2010 Introductory Pasewark & Pasewark.
Reporting Aesthetics An ACEware Webinar 1:00-2:00 pm February 14 th, 2008.
About this template This template was designed to produce a 48x36 poster. You can modify it as needed for your presentation. By using this.
Example layout for an A1 poster presentation
CHAPTER 11 Tables. How Are Tables Used Data Display  Very tidy and very useful Better Text Alignment  Putting text in tables allows you to format indents.
Data Visualisation A picture is worth a thousand words.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
MDS-NX The next generation of MDS... MDS-NX Overview.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
1 Web Developer Foundations: Using XHTML Chapter 4 Key Concepts.
PowerBuilder Online Courses - by Prasad Bodepudi
Pasewark & Pasewark 1 Access Lesson 5 Creating and Modifying Reports Microsoft Office 2007: Introductory.
1 Using HTML and JavaScript to Develop Websites. Using Images.
Intro to PHP Carl-Erik Svensson. What is PHP? PHP is a widely-used general-purpose scripting language that is especially suited for Web development and.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Adding Images. XHTML Element ElementAttributeAttribute Value Closing tag AttributeAttribute Value The src attribute supplies the name and location of.
© 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Lecture 29 Enhancing Presentations with Graphics (2)
Pasewark & Pasewark 1 Access Lesson 5 Creating and Modifying Reports Microsoft Office 2007: Introductory.
Walkthrough example including SAS output How to create a mobile WebApp? PhUSE / 12. October 2015 / Katja Glaß BHC 4:3 Template 2010 June 2014Page 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
The Web Wizard’s Guide to HTML Chapter Three Colors, Patterns, and Inline Graphics.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Access Lessons 4 and 5 © 2009 M and K Solutions, LLC -- All Rights Reserved.
CPSC 203 Introduction to Computers T43, T46 & T68 By Jie (Jeff) Gao.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
GD Library in PHP CH. Pradeep Reddy Assistant Professor VIT University, Vellore.
Professional Template for a 48x36 poster presentation
[Charts| Generating Graphic| Creating Graphic]
Permeability (% of Control)
Permeability (% of Control)
Office tool for creating tables and charts
Professional Template for a 48x36 poster presentation
Professional Template for a 48x36 poster presentation
Microsoft Office Access 2003
Web Systems Development (CSC-215)
Microsoft Office Access 2003
Professional Template for a 80(width) x 100(height) cm2 poster presentation Your name and the names of the people who have contributed to this presentation.
Use a Large Bold Type for the Main Title (80 pt):
Permeability (% of Control)
Use a Large Bold Type for the Main Title (80 pt):
Use a Large Bold Type for the Main Title (70 pt):
Permeability (% of Control)
Use a Large Bold Type for the Main Title (70 pt):
Presentation transcript:

PHP Sample Application Simple graphics and database

Sample PHP Application PHP is commonly used to: –Draw graphics on the fly –Access a database Let’s put these together to make an application that: –Lets a user make a query on a web form –Looks up some data from an Access database (similar if using SQL database) –Displays a graph of the data from the database

Simple Graphics First, let’s see how to draw some simple graphics PHP 5 includes the “GD” graphics library, created by Boutell.com PHP 4 requires an extension be added to access this library PNG format used –Similar but superior to GIF –GIF patented by Unisys, expired 2003

Base image functions image imagecreate(width,height) –Creates and returns an image of specified height color imagecolorallocate(image, R,G,B) –Creates a color for image with the given Red, Green, and Blue colors boolean imagefill(image, x, y, color) –Flood fills at the given point with the given color header("Content-type: image/png"); –Displays the MIME header for a PNG image imagepng(image) –Displays the data for the PNG image

Example: Green image <? $image = imagecreate(300,200); $colorGreen = imagecolorallocate($image, 0, 255, 0); imagefill($image, 0, 0, $colorGreen); header("Content-type: image/png"); imagepng($image); ?>

More image functions imagestring (image, int font, int x, int y, string s, int col) –Draws the string s in the image at coordinates x, y in color col. If font is 1, 2, 3, 4 or 5, a built-in font is used. imagefilledrectangle(image, x1,y1, x2,y2,color) –Draws a filled rectangle at upper left corner x1,y1 bottom right corner x2,y2 imagefilledellipse(image, x1,y1, width,height,color) –Draws a filled ellipse in the bounding rectangle specified by x1,y1,x2,y2 imagerectangle(image,x1,y1,x2,y2,color) –Rectangle with no fill imageellipse(image, x1,y1, width,height,color) –Ellipse with no fill

Image example <? $image = imagecreate(300,200); $colorWhite = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $colorWhite); imagefilledrectangle($image, 50,50, 100, 75, imagecolorallocate($image,255,0,0)); imageellipse($image, 150, 50, 100, 50, imagecolorallocate($image,0,0,255)); imagestring($image, 0, 10, 10, "Hello!", imagecolorallocate($image,0,0,0)); header("Content-type: image/png"); imagepng($image); ?>

ImagePolygon and ImageLine <? $image = imagecreate(300,200); $colorWhite = imagecolorallocate($image, 255, 255, 255); imagefill($image, 0, 0, $colorWhite); $colorBlack = imagecolorallocate($image, 0, 0, 0); imageLine($image, 50, 0, 200, 150, $colorBlack); $pointsTriangle = array(50, 10, 10, 90, 90, 90); imagePolygon($image, $pointsTriangle, count($pointsTriangle)/2, $colorBlack); header("Content-type: image/png"); imagepng($image); ?> How could you display this image multiple times in a web page?

Many more image functions Read jpg, gif, etc. Rotate, blending Resize Draw arcs Gamma correct Tiling … PHP Reference or textbook is a great way to learn about these functions, with code samples

Drawing Graphs What if you wanted to draw charts and graphs? –Pie chart, bar chart, line chart, scatter plot, etc. –You could do it using the graphics primitives we have covered Fortunately, someone has already done this for you –JPGraph Library –

JPGraph Samples See test suite with code samples….

Let’s look at a simple bar chart <?php include ("jpgraph2/jpgraph.php"); include ("jpgraph2/jpgraph_bar.php"); $datay=array(12,8,19,3,10,50); $datax=array(10,20,30,40,50,60); // Create the graph. These two calls are always required $graph = new Graph(300,200,"auto"); $graph->SetScale("textlin");// Natural nums // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->img->SetMargin(40,30,20,40); // Create a bar plot $bplot = new BarPlot($datay); $graph->Add($bplot);

Simple Bar chart, cont. // Add data to X coordinate // $graph->xaxis->SetTickLabels($datax); // Create and add a new text $txt=new Text("This is a text"); $txt->SetPos(0,0); $txt->SetColor("red"); $graph->AddText($txt); // Setup the titles $graph->title->Set("A simple bar graph"); $graph->xaxis->title->Set("X-title"); $graph->yaxis->title->Set("Y-title"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); // Display the graph $graph->Stroke(); ?>

Database Access Changing directions, reading from a database and displaying data in a graph –In our example, let’s read from a MySQL “Test” database with name popularity over the decades name yr1900 yr1910 … yr2000 –PHP app: let the user enter a name then graph the popularity

Database Schema

Building our App First, make a form that asks for a username and then retrieves and prints all the yearly data that matches the name in the table

<?php header("Content-Type: text/html"); print(" Name Popularity Surfer "); print(" "); if($_SERVER['REQUEST_METHOD'] != "POST") { print(" "); print("Enter name. "); print(" "); }

else { $name = $_REQUEST['name']; // Database parameters $db_location = "localhost"; $db_user_name = "test"; $db_password = "test"; $database_name = "test"; // Connect to the DB $dbcnx = mysql_connect($db_location,$db_user_name,$db_password); mysql_select_db($database_name); $sql="SELECT * FROM names where name='". $name. "';"; $rs=mysql_query($sql);

if ($row = mysql_fetch_assoc($rs)) { $arr = array(); $arr[] = $row['yr1900']; for ($i = 10; $i < 100; $i+=10) $arr[] = $row['yr19'. $i]; $arr[] = $row['yr2000']; print_r($arr); print(" "); } if (!isset($arr)) print("$name not found in the database."); } print(" "); ?>

Drawing Graph Now let’s hook this up with jpgraph to draw a graph of the popularity over time You could run this yourself if you copy/install the jpgraph folder to your own HTML folder –Can access database from any account using the supplied username/password

Tie-In Graphics <?php include("jpgraph.php"); include("jpgraph_line.php"); if($_SERVER['REQUEST_METHOD'] != "POST") { print(" "); print("Enter name. "); print(" "); } else { $name = $_REQUEST['name']; // Database parameters $db_location = "localhost"; $db_user_name = "test"; $db_password = "test"; $database_name = "test"; // Connect to the DB $dbcnx = mysql_connect($db_location,$db_user_name,$db_password); mysql_select_db($database_name);

Tie-In Graphics $sql="SELECT * FROM names where name='". $name. "';"; $rs=mysql_query($sql); if ($row = mysql_fetch_assoc($rs)) { $ydata = array(); $xdata = array(); $ydata[] = $row['yr1900']; $xdata[] = 1900; for ($i = 10; $i < 100; $i+=10) { $ydata[] = $row['yr19'. $i]; $xdata[] = $i; } $ydata[] = $row['yr2000']; $xdata[] = 2000; // Create the graph. These two calls are always required $graph = new Graph(600,400,"auto"); $graph->SetScale("linlin"); // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->img->SetMargin(40,30,20,40); // Create a line plot $lplot = new LinePlot($ydata,$xdata); $lplot->SetColor("blue"); $lplot->SetWeight(2); $graph->Add($lplot); // Add data to X coordinate $graph->xaxis->SetTickLabels($xdata); // Setup the titles $graph->title->Set("Popularity for ". $name); $graph->xaxis->title->Set("Year"); $graph->yaxis->title->Set("Ranking"); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); // Display the graph $graph->Stroke(); } if (!isset($arr)) { header("Content-Type: text/html"); print(" Name Surfer "); print(" "); print("$name not found in the database."); print(" "); } ?>

Output

Summary We discussed how to integrate business graphics with a simple database web application Should have error checking for no user found, SQL injection, etc. Similar process for updating and modifying the database Very easy to make simple graphics Libraries for more complex graphs Overall it is fairly easy to create sophisticated web applications –Other environments like.NET encapsulate much of the primitive HTML information, e.g. datagrid