Customer:
Description:
Number:
Street:
City:
Province:
Postal Code:




Last nameFirst nameAddresses
AjerschAlexFarm: 725 Austin CourtCityHouse: 658 Timber LaneHome: 974 Tierney DriveFarm: 921 Timber LaneLake: 593 Timber LaneCottage: 386 Abbott Street EastVilla: 679 Allison AvenueVilla: 999 Dufferin RoadWork: 892 Sonesta Circlexxx: 33333 ssssxxx: 33333 ssssxxx: 33333 ssssTestDescription: 33333 TestStreetTestDescription: 33333 TestStreetTestDescription: 33333 TestStreetTestDescription: 33333 TestStreetTestDescription: 33333 TestStreetTestDescription: 33333 TestStreetTestDescription: 33333 TestStreet
AndersonMaseyHome: 439 Perrywood LaneHome: 748 Timber LaneHome: 481 Brouillette BoulevardLake: 413 Rideau Heights DriveCottage: 413 Perth StreetCityHouse: 221 Century Road EastHome: 466 Rosebery AvenueFarm: 82 Fireside CrescentWork: 617 Tierney DriveVilla: 961 Rideau Heights DriveWork: 399 Perrywood LaneHome: 58 Elliot AvenueVilla: 165 Kathleen CrescentTestDescription: 33333 TestStreetTestDescription: 33333 TestStreet
AshbyEthanLake: 937 Cohen AvenueCottage: 172 Earl Mulligan DriveLake: 608 10th Line RoadCityHouse: 18 Timber LaneVilla: 549 Fox Valley RoadWork: 662 Bottriell Way
BannerBruceLake: 967 Elliot AvenueCottage: 22 Akenhead CrescentLake: 872 Timber LaneWork: 499 Old Wellington StreetVilla: 283 Chipmunk StreetLake: 757 Caldwell AvenueFarm: 597 Severn AvenueVilla: 328 Singleton WayVilla: 458 Abbott Street EastVilla: 770 Berot Lane
BeeblebroxZaphodHome: 874 Baneberry CrescentWork: 413 Harvey StreetLake: 724 Earl Mulligan DriveWork: 36 Andrew StreetFarm: 820 Killeen Avenue
BlackJackVilla: 367 Brouillette BoulevardFarm: 459 Earl Mulligan DriveCityHouse: 995 Abbey RoadFarm: 780 Fox Valley RoadVilla: 410 Acton StreetCottage: 633 Beechfern DriveCottage: 224 Tierney DriveWork: 93 Dowler AvenueKickapoo: 67 Tenacious D StKickapoo: 67 Tenacious D StKickapoo: 67 Tenacious D StKickapoo: 67 Tenacious D StCity: 67 Street 67City: 67 Street 67City: 67 Street 67
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJackHoliday: 21 Broken Dreams Blvd
BlackJack
BlackJack
BlackJackHoliday: 21 Broken Dreams Blvd
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
BlackJack
CrosbieSammyFarm: 762 Corkery Woods DriveHome: 16 Aldercrest DriveLake: 780 Perrywood LaneCottage: 515 Corkery Woods DriveCityHouse: 680 Harvey StreetFarm: 715 Rideau Heights Drive
DelosLucasLake: 788 Perrywood LaneCottage: 49 Beechfern DriveVilla: 799 Rideau Heights DriveHome: 321 Bottriell WayLake: 651 Earl Mulligan DriveVilla: 302 Dallaire CrescentWork: 400 Indian Creek RoadHome: 755 Ottawa River Parkway
DentArthurHome: 684 Issam PrivateWork: 271 Glenbrook PlaceFarm: 911 Old Wellington StreetCottage: 522 10th Line RoadVilla: 34 Berot LaneWork: 163 Ottawa River ParkwayLake: 762 Beechfern DriveCityHouse: 215 Fox Valley RoadCottage: 441 Dowler AvenueLake: 501 Abbey Road
DowdallJaneCityHouse: 610 Killeen AvenueHome: 883 Fardon WayFarm: 819 Andrew StreetWork: 243 Caldwell AvenueCottage: 764 Sonesta CircleWork: 549 Dufferin RoadFarm: 440 Severn Avenue
GyetkoDanteLake: 493 Sonesta CircleCityHouse: 993 Regal CrescentVilla: 929 Earl Mulligan DriveVilla: 258 Dufferin RoadFarm: 38 Regal CrescentFarm: 523 Parkland CourtVilla: 8 Jeanne D'arc BoulevardCottage: 997 Earl Mulligan Drive
HamiltonsHelenCityHouse: 828 Dallaire CrescentVilla: 30 Jeanne D'arc BoulevardCityHouse: 11 Killeen AvenueWork: 388 Issam PrivateCityHouse: 228 Andrew StreetHome: 422 Century Road EastWork: 104 Perrywood LaneLake: 615 Corkery Woods DriveHome: 901 Sonesta CircleWork: 392 Orchard Hollow DriveWork: 314 Dallaire Crescent
HawkTonyVilla: 853 Berot LaneCityHouse: 696 Spruce Ridge RoadVilla: 918 Perrywood LaneVilla: 194 Brouillette BoulevardLake: 481 Heritage CourtHome: 199 Caldwell AvenueHome: 387 Rosebery AvenueCityHouse: 28 Chipmunk StreetLake: 992 Harvey StreetVilla: 910 Kathleen CrescentCottage: 192 Caldwell Avenue
HickmansJohnCottage: 424 Ottawa River ParkwayHome: 663 Sonesta CircleWork: 113 Indian Creek RoadCottage: 366 Fardon WayWork: 384 Hiram Wilson StreetCityHouse: 968 Garfield AvenueFarm: 351 Fardon WayVilla: 700 Perth StreetCityHouse: 213 Baneberry CrescentCityHouse: 103 Abbott Street EastFarm: 67 Bayshore DriveCityHouse: 634 Fardon Way
HolmesAzazHome: 417 Berot LaneCottage: 427 Kathleen CrescentCityHouse: 89 Hiram Wilson StreetVilla: 216 Perrywood LaneHome: 219 Sonesta CircleHome: 800 Caldwell AvenueWork: 690 Tierney DriveCityHouse: 414 Fireside CrescentCottage: 264 10th Line RoadHome: 289 Garfield Avenue
MooreAmeliaCottage: 935 Jeanne D'arc BoulevardLake: 225 Portage AvenueFarm: 749 Glenbrook PlaceHome: 89 Rosebery AvenueCityHouse: 117 Jeanne D'arc BoulevardWork: 264 Haanel DriveCottage: 793 Berot LaneVilla: 440 Brewer WayWork: 664 Graham Creek PrivateVilla: 808 Dufferin Road
MooreIsaacLake: 867 Heritage CourtVilla: 889 Hiram Wilson StreetCityHouse: 488 Fireside CrescentVilla: 208 Ottawa River ParkwayCottage: 664 Jeanne D'arc Boulevard
PicketDavisVilla: 966 Sonesta CircleHome: 335 Chipmunk StreetWork: 809 Akenhead CrescentHome: 314 Timber LaneCityHouse: 957 Austin Court
PinkyJackHome: 940 Fardon WayHome: 145 Harvey StreetCottage: 283 Corkery Woods DriveCottage: 541 Fox Valley RoadVilla: 548 Kathleen CrescentFarm: 952 Harvey StreetLake: 39 Andrew StreetWork: 283 Chipmunk Street
ScottMichaelWork: 304 Elliot AvenueCityHouse: 183 Berot LaneHome: 926 Akenhead CrescentLake: 256 Timber LaneFarm: 469 Elliot Avenue
SmithElaHome: 344 Garfield AvenueWork: 80 Fireside CrescentCityHouse: 817 Evangeline StreetCottage: 727 Parkland CourtVilla: 121 Brouillette BoulevardVilla: 462 Century Road EastHome: 399 Denali WayCityHouse: 794 Saulnier LaneFarm: 251 Queensdale AvenueFarm: 503 Old Wellington Street
TrumpetJoshuaCottage: 251 Haanel DriveWork: 831 Regal CrescentHome: 418 Akenhead CrescentCityHouse: 58 Acton StreetFarm: 471 Heritage CourtWork: 609 Chipmunk StreetFarm: 884 Evangeline StreetLake: 393 Queensdale AvenueWork: 683 Rideau Heights Drive
WillowbeePutnumCottage: 763 Queensdale AvenueVilla: 945 Blazer AvenueLake: 61 Bayshore DriveFarm: 306 10th Line RoadFarm: 152 Bottriell WayLake: 792 Harvey StreetVilla: 156 Harvey StreetHome: 655 Baneberry CrescentCityHouse: 272 Graham Creek PrivateCottage: 173 Portage AvenueWork: 383 Evangeline StreetCityHouse: 742 Jeanne D'arc BoulevardLake: 547 Spruce Ridge RoadCottage: 92 Graham Creek Private




END OF OUTPUT




Source Code of php-db-challenge3-solution.php


<?php
require("database.php");
if(isset(
$_POST['desc'])){
    
// print_r($_POST);
    // Array
    // (
    //     [cust_id] => 33
    //     [desc] => Test Addr
    //     [num] => 42
    //     [street] => Hitchhiker's way
    //     [city] => Southampton
    //     [prov] => ON
    //     [postal] => H0H0H0
    // )
    
$q $pdo->prepare("INSERT INTO addresses (addr_cust,addr_desc,addr_number,addr_street,addr_city,addr_prov,addr_postal)
                                            values(:cust,:desc,:num,:street,:city,:prov,:postal)"
);
    
$q->bindParam("cust",$_POST['cust_id']);
    
$q->bindParam("desc",$_POST['desc']);
    
$q->bindParam("num",$_POST['num']);
    
$q->bindParam("street",$_POST['street']);
    
$q->bindParam("city",$_POST['city']);
    
$q->bindParam("prov",$_POST['prov']);
    
$q->bindParam("postal",$_POST['postal']);

    
$q->execute();
    echo 
"Address Added";
}
?>
<!doctype HTML>
<html>
    <head>
    <style>
        table,tr,th,td {
            border:1px solid black;
            border-collapse:collapse;
        }
        th,td {
            padding: 5px;
        }
    </style>
    </head>
    <body>
<?php
    $query 
$pdo->prepare("SELECT * FROM customers ORDER BY cust_lname,cust_fname");
    
$query->execute();
    
$custs $query->fetchAll(PDO::FETCH_ASSOC);

    function 
getAddrs($custID) {
        global 
$pdo;
        
$query=$pdo->prepare("SELECT * FROM addresses WHERE addr_cust = :id");
        
$query->bindParam(":id",$custID);
        
$query->execute();
        
$addrs $query->fetchAll(PDO::FETCH_ASSOC);
        return 
$addrs;
      }
?>
        <form action="" method="POST">
            Customer: <select name='cust_id'>
                <?php 
                    
foreach($custs as $c) {
                        echo 
"<option value='".$c['cust_id']."'>".$c['cust_lname'].", ".$c['cust_fname']."</option>\n";
                    }
                
?>
                </select></br>
            Description: <input type="text" name='desc'></br>
            Number: <input type="text" name='num'></br>
            Street: <input type="text" name='street'></br>
            City: <input type="text" name='city'></br>
            Province: <select name='prov'>
                <?php 
                    
foreach(['AB'=>"Alberta",'BC'=>"British Columbia",'MB'=>"Manitoba",'NB'=>"New Brunswick",'NL'=>"Newfoundland",'NS'=>"Nova Scotia",'NT'=>"NW Territories",'NU'=>"Nunavut",'ON'=>"Ontario",'PE'=>"Prince Edward Island",'QC'=>"Quebec",'SK'=>"Saskatchewan",'YK'=>"Yukon"] as $code=>$prov) {
                        echo 
"<option value='$code'>$prov</option>\n";
                    }
                
?>
                </select></br>
            Postal Code: <input type="text" name='postal'></br>
            </select>
            <br>
            <input type="submit" value="ADD ADDRESS">
        </form>
        <br><br>
        <hr>
        <table>
      <tr><th>Last name</th><th>First name</th><th>Addresses</th></tr>
        <?php
foreach ($custs as $c) {
    echo 
"<tr><td>".$c['cust_lname']."</td><td>".$c['cust_fname']."</td>";
    foreach(
getAddrs($c['cust_id']) as $a) {
  
// print_r($a);
  // [addr_id] => 1
  // [addr_cust] => 1
  // [addr_desc] => Addr1
  // [addr_number] => 3088
  // [addr_street] => Dunrobin Rd
  // [addr_city] => Dunrobin
  // [addr_prov] => ON
  // [addr_postal] => K0A1T0
      
echo "<td><b>".$a['addr_desc']."</b>: ".$a['addr_number']." ".$a['addr_street']."</td>";
    }
    echo 
"</tr>\n";
  }
        
?>
    </table>
    <?php //WILL DISPLAY CODE OF THIS FILE ON THE WEBPAGE//
######################################################################
echo "<br/><br/><hr><hr>";
echo 
"<h2 style='text-align:center'>END OF OUTPUT</h2>\n";
echo 
"<hr><hr>";
echo 
"<h2><br>Source Code of ".basename((string)__FILE__) . "</h2><hr>";
show_source(__FILE__);
#######################################################################
?>

    </body>
</html>