HTML Table and PHP Array

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

Cascading Style Sheets
Chapter 7: Introduction to Debugging TECH Prof. Jeff Cheng.
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen automatically using rand() function.
NUMERIC ARRAYS DEBBI HAMNER CIT 336 TEACHING PRESENTATION.
JavaScript 101 Lesson 01: Writing Your First JavaScript.
IST 221 Internet Concepts and Applications Introduction to PHP.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010 All Rights Reserved. 1.
HTML Recall that HTML is static in that it describes how a page is to be displayed, but it doesn’t provide for interaction or animation. A page created.
Web Page Development Identify elements of a Web Page Start Notepad
Chapter 7 To Err Is Human: An Introduction to Debugging.
PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
Chapter 4 Mixing PHP and HTML  In this chapter, you’ll learn how to do the following: -Recognize and use the different kinds of PHP start and end tags.
Basic XHTML Module 2: XHTML Basics LESSON 1. Module 2: XHTML Basics LESSON 1 Lesson Overview In this lesson, you will learn to:  Write XHTML code using.
PHP : Hypertext Preprocessor
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
HTML Basic I IST2101. Keep In Mind Programming can be time consuming. Plan ahead!
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
PHP meets MySQL.
G053 Lecture 12 Introduction To HTML Mr C Johnston ICT Teacher
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
HTML Form and PHP IST Review of Previous Class HTML table and PHP array Winner is chosen randomly using rand() function.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Where does PHP code get executed?. Where does JavaScript get executed?
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
A LOTTERY GAME Assignment P2 IST Guideline Use the PHP you learnt in class to make a PHP page Game rules:
Exercise 1: IF/ELSE Step 1: Open NotePad++ and create “number.php” in your webspace Step 2: Write codes to do the following 1.Generate a random number.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired.
U:/msu/course/cse/103 Day 21, Slide 1 CSE 103 Makeups –If you didn’t take one over the weekend, take one TUESDAY or WEDNESDAY!
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
Simulation and Modeling: Predator-Prey Processing Lab IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 23, 2014 Carolyn Seaman Susan.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
HTML HYPER TEXT MARKUP LANGUAGE. INTRODUCTION Normal text” surrounded by bracketed tags that tell browsers how to display web pages Pages end with “.htm”
1 2/28/05CS120 The Information Era Chapter 4 Basic Web Page Construction TOPICS: Anchors and Tables.
HTML FORM Lab Exercise IST Guideline Add forms in your web page so that visitors can add a comment about your web page Forms should include the.
PHP (cont.). 2 Functions Definition – function name(arguments){... } –syntax name as for a variable, but without $ arguments as for variables –to return.
Introduction to PHP 1.What is PHP? What Is PHP?  php: hypertext preprocessor  Server-side scripting language—like ASP—scripts are executed on server.
Using Text Edit. Create Folders to Organize a Site  Identify the location where you are storing your Web sites. Ask your teacher for help if needed.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
HTML FORM AND PHP IST 210: Organization of Data IST210 1.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP ARRAY AND HTML TABLE IST 210 Organization of Data IST210 1.
PHP AND SQL SERVER: QUERIES IST 210: Organization of Data IST210 1.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
CGS 3066: Web Programming and Design Spring 2016 PHP.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP Array and HTML Table IST 210 Organization of Data IST2101.
PHP and SQL Server: Connection IST 210: Organization of Data IST2101.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
PHP AND SQL SERVER: CONNECTION IST 210: Organization of Data IST210 1.
Programming Assignment 4: HTML Table and PHP Array.
Presentation transcript:

HTML Table and PHP Array

Tips in Debugging What’s wrong with my code? IST210

Tips in Debugging Identify errors by systematically commenting out and running parts of your code Use // to comment out a line Use /* and */ to comment out a segment of codes IST210

Bug must be in this line! So let’s fix it! echo "Your number is <font size=5 color=\"green\"> $y </font> <br>"; IST210

Learn to Debug Bad question “What’s wrong with my code?” “I have no clue why it is not working” You need to identify the specific location and/or the specific problem in your code, and then ask questions like “Am I using the dots and quotation marks in this echo command correctly?” “Can you explain to me what’s the difference between A==B and A=B?” Knowing how to debug is a very important skill ! Totally ok to make mistakes You are encouraged to make mistakes! But you need to know where is the mistake, how to fix it, and how to avoid making the same mistake again.  that’s how you gradually become an expert in programming (a.k.a, geek)  IST210

HTML Table Tables Elements Format data in a way that can be easily comprehended Elements Table Headings Rows Data IST210

An Example of HTML Table <html> <body> <table border="1"> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <td>John</td> <td>Smith</td> <td>Anthony</td> <td>Kim</td> </table> </body> </html> IST210

Exercise: Table Step 1. Open NotePad++ Step 2. Write HTML code to generate the table on the right Step 3. Save it to “color.html” to your webspace Step 4. Open a web browser, and visit http://my.up.ist.psu.edu/PSUID/color.html Observation: HTML will become very long as the table size grows.

PHP Array Array is a data structure that allows you to manage a list of data easily. Color list: red, yellow, blue It is not efficient to use a variable to represent each value. $color1= "red"; $color2 = "yellow"; $color3 = "blue";

Use Array in PHP Color list {"red", "yellow", "blue"} $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; Like C/C++, PHP uses 0-based numbering Array name Key

Use Array in PHP <?php $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; echo $color[0]."<br>"; echo $color[1]."<br>"; echo $color[2]."<br>"; ?>

Using For Loop to Retrieve Array Values <?php $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; for ($i=0; $i<3; $i++) { echo $color[$i]."<br>"; } ?>

Using Foreach Loop to Retrieve Array Values <?php $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; foreach ($color as $currentcolor) { echo $currentcolor."<br>"; } ?> No need to know the length of the array

Initialization of Array Start with index 0 $color[0] = “red” $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; $color = array ("red", "yellow", "blue"); <?php $color = array ("red", "yellow", "blue"); foreach ($color as $currentcolor) { echo $currentcolor."<br>"; } ?>

Use PHP Array to Control HTML $color[0] = "red"; $color[1] = "yellow"; $color[2] = "blue"; foreach ($color as $currentcolor) { //print color tag echo "<font color=".$currentcolor." >"; //print color name echo $currentcolor; //print closing tag echo "</font><br>"; } ?>

Use PHP Array to Generate a HTML Table (Important!) PHP (dynamic & Efficient) HTML (Static & Inefficient) <html> <body> <table border="1"> <tr> <th>id</th> <th>Color</th> </tr> <td>0</td> <td>red</td> <td>1</td> <td>yellow</td> <td>2</td> <td>green</td> </table> </body> </html> <?php $color = array ("red", "yellow", "green"); echo "<table border=1>"; echo "<tr>"; echo "<th>id</th>"; echo "<th>Color</th>"; echo "</tr>"; for ($i=0; $i<3; $i++) { echo "<td>$i</td>"; echo "<td>$color[$i]</td>"; } echo "</table>"; ?> Try it DO NOT USE IST210

More Examples on Loop and Array For loop http://php.net/manual/en/control-structures.for.php Foreach loop http://php.net/manual/en/control-structures.foreach.php While loop http://php.net/manual/en/control-structures.while.php Array http://php.net/manual/en/language.types.array.php IST210

In-Class Exercise Create a PHP file for a Lucky Draw game among at least five students Use arrays to store the 5 students’ last name, first name and major Hint: Use 3 arrays. E.g., $lastname = array ('Smith', 'Kim', 'Davis', 'Miller', 'Taylor'); Display the students’ information in a table using FOR Loop Hint: use echo to output the table to HTML Randomly select a student, for each time the PHP page is visited/refreshed, as the winner of the game, and display his/her name Hint: you can use “$v = rand(0,4)” to generate a random number in [0,4] and store it in $v Visit your PHP file: http://my.up.ist.psu.edu/USERNAME/FILENAME

In-Class Exercise (cont.) http://my.up.ist.psu.edu/zuz22/table_lottery.php