Skip to Content
Web Database Applications with PHP and MySQL, 2nd Edition
book

Web Database Applications with PHP and MySQL, 2nd Edition

by Hugh E. Williams, David Lane
May 2004
Intermediate to advanced
820 pages
24h 34m
English
O'Reilly Media, Inc.
Content preview from Web Database Applications with PHP and MySQL, 2nd Edition

Freight Calculator Example

The examples we have shown so far in this chapter have been contrived to help illustrate the features of PHP. In this section, we apply these techniques and features discussed in this chapter to improve the freight calculator example we introduced in Chapter 4.

Review of the FreightCalculator

The FreightCalculator class defined in Example 4-9 is used to calculate the cost of delivering an online order. Example 4-9 also define the AirFreightCalculator class that redefines the two protected member functions that do the work of calculating the cost components: perKgTotal( ) and perCaseTotal( ).

FreightCalculator objects, including AirFreightCalculator objects, are constructed with two parameters, the total weight and the number of cases that make up a delivery:

    function _  _construct($numberOfCases, $totalWeight)
    {
        $this->numberOfCases = $numberOfCases;
        $this->totalWeight = $totalWeight;
    }

We also defined the CaseCounter class in Example 4-8 that extends the simple UnitCounter class defined in Example 4-4. A CaseCounter object can be used to accumulate units that make up a delivery and calculate the total weight and number of cases required to pack the order. The following example shows how a CaseCounter is created and used:

// Access to the CaseCounter class definition require "example.4-8.php"; // Create a CaseCounter object where there are // 12 units to a case, and each unit weights 1.2 Kg. $myOrder = new CaseCounter(12, 1.2); // Add 5 bottles $myOrder->add(5); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Web Database Applications with PHP, and MySQL

Web Database Applications with PHP, and MySQL

Hugh E. Williams, David Lane

Publisher Resources

ISBN: 0596005431Errata Page