Download presentation
Presentation is loading. Please wait.
1
IS1500: Introduction to Web Development
Dynamic Websites with PHP Martin Schedlbauer, Ph.D.
2
Dynamic Websites with PHP
IS4300 Dynamic Websites Websites with just content pages are called static websites. Dynamic websites collect data and display pages that are generated right before being sent to the browser. IS1500 Dynamic Websites with PHP
3
Example of a Static Website
Adding additional players requires that a web developer modify the page and then republish the page. This is time consuming, error prone, and expensive. IS1500 Dynamic Websites with PHP
4
Better Approach: Dynamic Pages
Why not put the information into a database and then write code to extract the information and build a page programmatically? Then, to modify the page, only add additional data to the database. IS1500 Dynamic Websites with PHP
5
Dynamic Page Generation
From IS1500 Dynamic Websites with PHP
6
Dynamic Websites with PHP
Scripting Engines There are several server-side scripting engines that use different programming languages: PHP as the scripting language accessing data from a relational database, most commonly MySQL Ruby on Rails using MySQL ASP.NET using SQL Server or Microsoft Access IS1500 Dynamic Websites with PHP
7
Common Technology Stacks
LAMP/WAMP: Linux or Windows as the server operating system Apache as the web server MySQL as the database PHP as the dynamic page scripting language IS1500 Dynamic Websites with PHP
8
Dynamic Websites with PHP
Our Stack We are using a simplified stack requiring less programming experience: Hosted server (AwardSpace/Weebly) Hosted web development platform (AwardSapce) Database (MySQL) Dynamic page scripting language (PHP) IS1500 Dynamic Websites with PHP
9
Dynamic Page Generation in PHP
Internet Generated HTML PHP Program HTML + PHP Script Database Browser IS1500 Dynamic Websites with PHP
10
Data: Definition & Generation
A database is a collection of tables containing records each of which has fields. The MySQL database is a “relational database”. Administration is done through the PHPAdmin3 web tool. IS1500 Dynamic Websites with PHP
11
Steps for Creating Dynamic Pages
create a database define tables for the database add data to the database or build a form that collects data and stores it in the tables write PHP program to build HTML page with data from database integrate PHP program into website IS1500 Dynamic Websites with PHP
12
Dynamic Websites with PHP
Step 4: The PHP Program <?php $servername = "pdb18.awardspace.net"; $username = " _bruins"; $password = "4BostonBruins"; $database = " _bruins"; $port = "3306"; // Create connection $conn = mysqli_connect($servername, $username, $password, $database, $port); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "SELECT * FROM players"; $result = $conn->query($sql); if ($result->num_rows > 0) { // create table structure echo "<table border=0>"; // output data of each row: a single player with picture and name while($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td><img src='" . $row["p_image"] . "' width=100 height=120/></td>"; echo "<td valign=top style='color:darkgray'>"; echo $row["p_name"]. " (" . $row["p_pos"]. ")</td>"; echo "</tr>"; echo "</table>"; } else { echo "0 results"; ?> IS1500 Dynamic Websites with PHP
13
PHP: Connecting to the Database
$servername = "pdb18.awardspace.net"; $username = " _bruins"; $password = "4BostonBruins"; $database = " _bruins"; $port = "3306"; // Create connection $conn = mysqli_connect($servername, $username, $password, $database, $port); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } IS1500 Dynamic Websites with PHP
14
PHP: Retrieving Data with SQL
$sql = "SELECT * FROM players"; $result = $conn->query($sql); This is the name of the table you created in the MySQL database. Look at the table names using PHPAdmin3 IS1500 Dynamic Websites with PHP
15
PHP: Displaying the Data by Row
if ($result->num_rows > 0) { // create table structure echo "<table border=0>"; // output data of each row: a single player with picture and name while($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td><img src='" . $row["p_image"] . "' width=100 height=120/></td>"; echo "<td valign=top style='color:darkgray'>"; echo $row["p_name"]. " (" . $row["p_pos"]. ")</td>"; echo "</tr>"; } echo "</table>"; This is the name of the column you specified when you created the table. <table border=0> <tr><td><img src=' width=100 height=120/></td> <td valign=top style='color:darkgray'>Tuuka Rask (Goalie)</td></tr> <tr><td><img src=' width=100 height=120/></td> <td valign=top style='color:darkgray'>Patrice Bergeron (Forward)</td></tr> <tr><td><img src=' width=100 height=120/></td> <td valign=top style='color:darkgray'>Brett Connolly (Forward)</td></tr> </table> IS1500 Dynamic Websites with PHP
16
Dynamic Pages in Summary
IS4300 Dynamic Pages in Summary MySQL Database 1. define database 3. Retrieve data and generate dynamic page via script 2. add data to database IS1500 Dynamic Websites with PHP
17
Dynamic Websites with PHP
Embedding into HTML The simplest way is to add the URL as embedded <iframe> HTML tag: <iframe src=" width='100%'> </iframe> IS1500 Dynamic Websites with PHP
18
Dynamic Websites with PHP
Database Checklist Tables name should not contain spaces Column names should not contain spaces Ensure that every table has a primary key which is generally a numeric ID field IS1500 Dynamic Websites with PHP
19
Summary, Review, & Questions…
IS1500 Dynamic Websites with PHP
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.