_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Keys, Referential Integrity and PHP One to Many on the Web.
Web Database Programming Connecting Database to Web.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
PHP (2) – Functions, Arrays, Databases, and sessions.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Objectives Connect to MySQL from PHP
Website Development & Management PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT Fall
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
INTERNET APPLICATION DEVELOPMENT For More visit:
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
Server-side Scripting Powering the webs favourite services.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
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 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
PHP meets MySQL.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
1 OPOL Training (OrderPro Online) Prepared by Christina Van Metre Independent Educational Consultant CTO, Business Development Team © Training Version.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
MS Access 2007 Management Information Systems 1. Overview 2  What is MS Access?  Access Terminology  Access Window  Database Window  Create New Database.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Chapter 10 Database Management. Data and Information How are data and information related? p Fig Next processing data stored on disk Step.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
mysql and mysql workbench
ISC440: Web Programming 2 Server-side Scripting PHP 3
In Class Programming BIS1523 – Lecture 11.
Presentation transcript:

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the book authors, 2002 PHP Bible Chapter 16: Displaying Queries In Tables

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition2  Wiley and the book authors, 2002 Summary Mapping database tables to HTML tables Reusable functions for table display using SELECT Displaying complex relational table data

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition3  Wiley and the book authors, 2002 Displaying queries in tables Much of the point of PHP is to help you translate between a back-end database and its front-end presentation on the Web Data can be viewed, added, removed, and tweaked as a result of your Web user's actions The 2 big productivity points from this chapter are:  Reuse functions in simple cases. The problem of database table display shows up over and over in database-enabled site design. If the display is not complicated, you should be able to throw the same simple function at the problem rather than reinventing the wheel with each PHP page you write  Choose between techniques in complex cases. You may find yourself wanting to pull out a complex combination of information from different tables (which, of course, is part of the point of using a relational database to begin with). You may not be able to map this into a simple reusable function, but there aren't that many novel solutions either – get to know the alternatives, and you can decide how to trade off efficiency, readability, and your own effort

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition4  Wiley and the book authors, 2002 HTML tables and database tables One-to-one mapping  HTML tables are really constructed out of rows ( ), and columns have no independent existence – each row has some number of table data items ( ) which will produce a nice rectangular array only if there are the same number of TDs for every TR within a TABLE  By contrast, fields (aka columns) in database tables are the more primary entity – defining a table means defining the fields, and then you can add as many rows as you like  The simplest case of display is where the structure of a database table or query does correspond to the structure of the HTML table we want to display – the database entity has m columns and n rows, and we'd like to display an m-by-n rectangular grid in the user's browser window, with all the cells filled in appropriately

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition5  Wiley and the book authors, 2002 HTML tables and database tables (cont.) Example: a single-table displayer  So let's write a simple translator that queries the database for the contents of a single table and displays the results on screen. Here's the top-down outline of how the code will get the job done: 1. Establish a database connection ( mysql_connect & mysql_select_db ) 2. Construct a query to send to the database (SELECT) 3. Send the query and hold on to the result id ( mysql_query ) 4. Start outputting an HTML table ( ) 5. Loop through the database result rows, printing an HTML table row tag set ( ) at the beginning and ending of each loop 6. On the first execution of the loop, if desired, print out the field names 7. In each row, retrieve the successive fields and display them wrapped in a table data cell ( ) 8. Close the HTML table ( )  We'd like to wrap all the preceding steps into a handy function that we can use whenever we want to

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition6  Wiley and the book authors, 2002 HTML tables and database tables (example) <?php include ('/home/php/db_vars.inc'); function display_db_table($table,$db_res,$criteria='',$field_headings=true) { $sql = 'SELECT * FROM '.$table.' '.$criteria; $result_id = mysql_query($sql,$db_res) or die ('ERROR executing query'); print(' '); if ($field_headings) $heading_printed = false; else $heading_printed = true; while ($row = mysql_fetch_assoc($result_id)) { if (!$heading_printed) { print (' '); foreach ($row as $field_name => $val) print (' '.$field_name.' '); print (' '); $heading_printed = true; } print (' '); foreach ($row as $val) print (' '.$val.' '); print (' '); } print (' '); }

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition7  Wiley and the book authors, 2002 HTML tables and database tables (example) $db_resource = mysql_connect($hostname,$username,$password); mysql_select_db($db_name,$db_resource); if (isset($_GET['category'])) { $category_num = $_GET['category']; $sql = 'SELECT description FROM categories WHERE (category_id = '.$category_num.')'; $result_id = mysql_query($sql,$db_resource); $row = mysql_fetch_row($result_id); $category = $row[0]; $criteria = 'WHERE (category='.$category_num.')'; } else { $category = 'All Products'; $criteria = ''; } ?> Available products in <?php print (' '.$category.' '); display_db_table('catalog',$db_resource,$criteria); ?>

_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition8  Wiley and the book authors, 2002 HTML tables and database tables (cont.) Some things to notice about the preceding script:  Although the script refers to specific database tables, the display_db_table() function itself is general. You could put the function definition in an include file and use it anywhere you want  The first thing the script does is load an include file that contains the variable assignments for the database name, username, password, and server name  In the function, we use a while loop for printing rows, and a foreach loop to print the individual fields from each row  The main while loop reflects a very common idiom, which exploits the fact that the value of a PHP assignment statement is the condition. $row will either contain an array of the record returned from the SELECT statement or the value FALSE  The main body of the function shows a relationship between the catalog table and the categories table where the catalog.category field is a foreign key "pointing to" the categories.category_id field  The main body also looks for a category GET variable which could be entered into a URI in an HTML hyperlink ( ) or typed into the address line