Tables from Arrays of Objects Exploding Strings

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Designing a Database Unleashing the Power of Relational Database Design.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 6: Loop Control Structures.
COMP101 – Exploring Multimedia and Internet Computing LA2 (Thu 14:00 – 16:50) TA: Jackie Lo.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 2.
HTML & PHP What’s the difference?. HTML Hypertext Markup Language Key Word is “Markup” HTML is the code that makes the “screen” All web pages are made.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
Creating Databases applications for the Web: week 2 Basic HTML review, forms HW: Identify unique source for asp, php, Open Source, MySql, Access.
Web Database Programming Using PHP
>> Fundamental Concepts in PHP
Expressions and Control Flow in PHP
Databases.
Miscellaneous Excel Combining Excel and Access.
Repetition Structures
BIT116: Scripting Loops.
Loops BIS1523 – Lecture 10.
Arrays: Checkboxes and Textareas
Database Normalization
Data Virtualization Tutorial: XSLT and Streaming Transformations
Web Database Programming Using PHP
Arrays in PHP are quite versatile
JSL File manager Brady Brady and Don Mccormack, JMP.
Reading Netpbm Images.
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
Arrays and files BIS1523 – Lecture 15.
Incrementing ITP © Ron Poet Lecture 8.
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
Lecture 10: Buffer Manager and File Organization
While Loops BIS1523 – Lecture 12.
* Lecture 26 Manifest Asynchrony
Server Side Programming Overview And file system basics
Introduction to Databases with MAMP/LAMP/WAMP thrown in!
CT Web Development, Colorado State University
* Lecture 12 Mapping, Map Reduction Summing integers,
HTML5 Drawing Canvas and Video
Learning to Program in Python
JavaScript Charting Library
Handling Files In particular, uploading files.
Content Management and WordPress
HTML Basics & Context & IDEs & Server Basics & Online Notes
Python I/O.
Functions BIS1523 – Lecture 17.
* Lecture 22 Images * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
Introduction to AJAX and the migration toward applications
MySQL Tables and Relations 101
* Lecture 5 PHP Basics * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
Derived types.
Querying Client Information Forms and Passing Data,
* jQuery * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
Authentication Stepped Up Persistent User Data Protected Content.
Web DB Programming: PHP
Repetition Structures
IntroductionToPHP Static vs. Dynamic websites
HOW TO MAKE PAGES FOR A WEB SITE
PROG Advanced Web Apps 2/24/2019 Session 9.2 Data Binding Wendi Jollymore, ACES.
Server Side Programming Overview And file system basics
How to use hash tables to solve olympiad problems
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Loops and Conditionals Generating , Reading files.
Unit 10 The Web Book Test.
Programming with Microsoft Visual Basic 2008 Fourth Edition
SQL – Application Persistence Design Patterns
Alternatives to our approach
Reading information from files
Introduction to Computer Science
Chapter 13 Control Structures
Presentation transcript:

Tables from Arrays of Objects Exploding Strings * Lecture 13 Tables from Arrays of Objects Exploding Strings * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 5 combines: Objects Arrays HTML Tables 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 05 Use objects to manage information A state is a singular thing with 3 related data items: 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Punchline: Transform an array of objects to a table 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz An Array of States Create three states in an array Note line 41: array holds all the member data for the first state. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

More about get_object_vars With one function you can fully equate object member data with a keyword style array. Access to the keys is very handy. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

Keys Are Column Headers Here again is a part of the code. Line 44: Object member data to an array Line 44: Retrieve keywords from array Line 45: Iterate through keys Line 46: One table column header per key. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Filling in the Table Enumerate the values in the table Upper and lower versions function the same. Lower avoids intermediate variable 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Style 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Now Without Loops Same goal, build a table from an array of objects. But, no loops, just array reduction Nested array reduction at that. Many ways this could be done. In this example, table header and table data rows first built as strings. Then sent to the client, i.e. a succinct echo command inside table tags. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 6 Code 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 06 on Client Think of it this way. Map reduce can be very good at constructing repeated patterns from arrays. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 06 Observations Example 06 may be a bit extreme OK to ask, who finds this more readable? On the plus side Highly functional limits side-effects. Internal function easy to modify. Punchline for CT 310 Study and understand Example 06! For now avoid loops when you can. Once you master both styles, then you will be able to make informed choices. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

Manipulating Files/Strings Here is a plain text file: As a text file, it has three lines What about if we want to Count words? Change newlines into HTML newlines? Group by words or lines? 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

First Part – Split on Newlines First, note one command reads file. Now, one command builds an array, one array entry per line. preg_split well worth studying! 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

Second Part – Word Counts Ever explode a string? Similar to preg_split, but simpler, and better if there is only one delimiter. Pay attention to the ease of word counting. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

Third Part - Substitution Explicitly convert ASCII newlines to line break tags. Note need to avoid counting <br> tags. 11/17/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz