Skip to content
/ php Public

Build websites using a programming language called PHP and how to store the data that the website uses in a database such as MySQL.

Notifications You must be signed in to change notification settings

mrbuzzgit/php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOWNLOAD THE CODE FOR THIS BOOK FROM

http://phpandmysql.com

TABLE OF CONTENTS

Introduction

  1. STATIC VARIABLE VS DYNAMIC WEBSITES
  2. PHP: THE LANGUAGE AND THE INTERPRETER
  3. PERFORMING A TASK USING DIFFERENT DATA
  4. WHAT IS A PHP PAGE?
  5. WHAT IS MYSQL?
  6. HISTORY OF PHP
  7. HISTORY OF MYSQL
  8. WHAT THIS BOOK COVERS
    • A. BASIC PROGRAMMING INSTRUCTIONS
    • B. DYNAMIC WEB PAGES
    • DATABASE DRIVEN WEBSITES
    • EXTENDING THE SAMPLE APPLICATION

Section A - Basic Programming Instructions

  1. INSTALLING SOFTWARE AND FILES
  2. DOWNLOADING THE SAMPLE CODE
  3. HOW PHP PAGES MIX HTML & PHP CODE

1. Variables, Expressions & Operators

VARIABLES

Variables store data that can change (or vary) each time a PHP page is requested. They use a name to represent a value that can change.

<?php 
$name  = 'Ivy';
$price = 5;
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Variables</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Welcome <?php echo $name; ?></h2>
    <p>The cost of your candy is 
       $<?php echo $price; ?> per pack.</p>
  </body>
</html>

Screenshot 2024-11-17 120054

<?php 
$name  = 'Guest';
$name  = 'Ivy';
$price = 5;
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Updating Variables</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Welcome <?php echo $name; ?></h2>
    <p>The cost of your candy is 
       $<?php echo $price; ?> per pack.</p>
  </body>
</html>

Screenshot 2024-11-17 120054

ARRAYS

A variable can also hold an array which stores a series of related values. Arrays are known as a compound data type because they can store more than one value.

ASSOCIATIVE ARRAYS

$member = [
'name'    => 'Ivy',
'age'     => 32,
'country' => 'Italy',
];
<?php 
$nutrition = [
    'fat'   => 16,
    'sugar' => 51,
    'salt'  => 6.3,
];
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Associative Arrays</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Nutrition (per 100g)</h2>
    <p>Fat:   <?php echo $nutrition['fat']; ?>%</p>
    <p>Sugar: <?php echo $nutrition['sugar']; ?>%</p>
    <p>Salt:  <?php echo $nutrition['salt']; ?>%</p>
  </body>
</html>

Screenshot 2024-11-17 125420

INDEXED ARRAYS

$shopping_list = ['bread', 'cheese', 'milk',];
<?php 
$best_sellers = ['Chocolate', 'Mints', 'Fudge',
    'Bubble gum', 'Toffee', 'Jelly beans',];
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Indexed Arrays</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Best Sellers</h2>
    <ul>
      <li><?php echo $best_sellers[0]; ?></li>
      <li><?php echo $best_sellers[1]; ?></li>
      <li><?php echo $best_sellers[2]; ?></li>
    </ul>
  </body>
</html>

Screenshot 2024-11-17 130022

UPDATING ARRAYS

Updating Associative array

$member['name'] = 'Tom';

Updating Indexed array

$shopping_list[2] = 'butter';
<?php 
$nutrition = [
    'fat'   => 38, 
    'sugar' => 51, 
    'salt'  => 0.25,
];
$nutrition['fat']   = 36;
$nutrition['fiber'] = 2.1;
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Updating Arrays</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Nutrition (per 100g)</h2>
    <p>Fat:   <?php echo $nutrition['fat']; ?>%</p>
    <p>Sugar: <?php echo $nutrition['sugar']; ?>%</p>
    <p>Salt:  <?php echo $nutrition['salt']; ?>%</p>
    <p>Fiber: <?php echo $nutrition['fiber']; ?>%</p>
  </body>
</html>

Screenshot 2024-11-17 143740

<?php 
$offers = [
    ['name' => 'Toffee', 'price' => 5, 'stock' => 120,],
    ['name' => 'Mints',  'price' => 3, 'stock' => 66,],
    ['name' => 'Fudge',  'price' => 4, 'stock' => 97,],
];
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Multidimensional Arrays</title>
    <link rel="stylesheet" href="css/styles.css">
  </head>
  <body>
    <h1>The Candy Store</h1>
    <h2>Offers</h2>
    <p><?php echo $offers[0]['name']; ?> -
      $<?php echo $offers[0]['price']; ?> </p>
    <p><?php echo $offers[1]['name']; ?> -
      $<?php echo $offers[1]['price']; ?> </p>
    <p><?php echo $offers[2]['name']; ?> -
      $<?php echo $offers[2]['price']; ?> </p>
  </body>
</html>

Screenshot 2024-11-17 145119

2. Control Structures

3. Functions

4. Object & Classes

About

Build websites using a programming language called PHP and how to store the data that the website uses in a database such as MySQL.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published