Pull All Records from a Database Table (i.e., clients table)

RECORDS
ID Name Address 1 Address 2 City State Zip Phone
1 Gorman Place 8 Horizon Road New Haven CT 06510 (336) 902-1538
2 Lavaysse Circus 27 Woodland Avenue San Mateo CA 94402 (211) 107-2844
3 Weisman Oil 3 Cindy Court Englewood NJ 07631 (276) 673-3707
4 Garrett Mag 83 Gentry Drive Melville NY 11747 (521) 333-7762
5 Carie Max Stores 236 Stanton Street Brookline MA 02446 (180) 351-8977
6 Mason Homes 587 Nathan Hale Road Bonita Springs FL 34134 (638) 895-7446
7 Bank of New York 2461 Riverside Dr. Apt. 9079 New York NY 10002 (123) 720-9779
8 Weitzman Construction 442 W. 98th St # 886 New York NY 10009 (736) 854-3262
9 Lambert Homes 841 central park west Apt. 774 St Davids PA 19087 (139) 523-8779
10 Rubin Sands 134 Iven Avenue Suite 2E New York NY 10024 (386) 634-8851
11 Rags to Riches Inc. 9739 85th Street New York NY 10003 (571) 811-5584
12 Jett Lee Sales 918 Central Ave. #313 Christiansted VI 00823 (841) 332-7923
13 Mcadams Investments Box 146 New York City NY 10003 (515) 650-2411
14 HallMark Rentals Livio Andronico 22 New York NY 10025 (534) 289-1364
15 Parson Computers 300 Knoll Blvd. Wayne NJ 07470 (279) 258-2678
16 Jenkinson Loan 8 Sundance Drive Main Road Mason MI 48920 (825) 281-8880
17 Minnick Lands 80 Hudson Street Suite 159 Bellevue WA 98004 (803) 918-7430
18 Scheiby Loans 5219 433th Ave SE Hastings-on-Hudson NY 10706 (129) 957-2662
19 Calvin Klien 32 Gray Gardens East Broadlands VA 20148 (793) 815-6116
20 Walker Floors 794 A Fairmont Ave. Hoboken NJ 07030 (351) 656-8438
21 Sherwood Oaks 1941 aberdeen way Davis CA 95616 (143) 275-2569
22 Coburn Homes 92525 N Meridian Pleasantville NY 10570 (365) 404-2548
23 Higgins Lakefront P.O. Box 664 Suite 384 Indianapolis IN 46290 (533) 230-4366
24 Davis Lodge 492 Locust Road Charlotte NC 28204 (164) 963-3123
25 Easter Travel 4114 W. Elm Suite 370 Stratham CA 03885 (330) 871-5564
26 Richman Buick PO BOX 4971 Boulder CA 80302 (131) 664-3716
27 Daly Autobody 4388 Folsom Street Suite 673 Santa Clara CA 95050 (642) 915-9286
28 Weston Electric 100 44th Ave.SE Suite 913A Glenview IL 60026 (486) 959-2036
29 Daves Diner 4585 W. Lake Norman OK 73026 (643) 147-7945
30 Eastman Rentals 600 Art Blvd. Lansing MI 48911 (158) 201-5442
31 Malcom Motors 5432 Sunset #A12 Charlotte SC 65432 (987) 543-8765

The following are the three files you will need to complete these assignments. Place these files in the 'examples' directory within your 'includes' directory. -- or -- Place them wherever you want, but then you must keep track of the paths.

Additionally, as said in class many times, DO NOT INCLUDE THESE FILES in your listing. It should be obvious that exposing the config file (containing user_id and password) would provide access to people outside this class!

These files are:

  1. config.php (configuration file)
  2. open-db.php (open db file)
  3. close.db (close db file)

<?php // config.php
    
$TUID 'YOUR_TUID';
    
$db_host 'localhost';
    
$db_name 'SEE ME';
    
$db_user 'SEE ME';
    
$db_pass 'SEE ME';
?>

<?php // open-db.php

    
$db_host '';
    
$db_name '';
    
$db_user '';
    
$db_pass '';

    require(
'config.php');
    
$con mysqli_connect($db_host$db_user$db_pass$db_name)
    or die (
'Error connect db: ' mysqli_error());
?>

<?php // close-db.php
mysqli_close($con);
?>
 

CODE FOLLOWS

<?php

    error_reporting
(E_ALL);    // set error reporting to all
    
include('includes/header.php');
    
$con '';

?>
    <h1>Pull All Records from a Database Table (i.e., clients table)</h1>

    <table class="full">        <!-- start of table -->
        <tr>
            <th colspan=8 class="header1">
                RECORDS
            </th>
        </tr>
        <tr class="header2">
            <th>ID</th>
            <th>Name</th>
            <th>Address 1</th>
            <th>Address 2</th>
            <th>City</th>
            <th>State</th>
            <th>Zip</th>
            <th>Phone</th>
        </tr>

        <?php

            
// get all records from the 'clients' table from the database

            
include('includes/open-db.php');    //====== open dB

            // SQL for selecting all records from the clients table where their id is > 0

            
$query "SELECT * FROM clients WHERE id > '0' ";
            
$result mysqli_query($con$query) or die("Could not get data: $query " mysqli_error());

            
// pull out and display those records

            
$i 0;
            while (
$row mysqli_fetch_array($result))
                {
                
$id $row['id'];
                
$name $row['name'];
                
$address_1 $row['address_1'];
                
$address_2 $row['address_2'];
                
$city $row['city'];
                
$state $row['state'];
                
$zip $row['zip'];
                
$phone $row['phone'];
                
?>

                    <tr class="row<?php echo($i++ & 1); ?>">
                        <td>
                            <?php echo($id); ?>
                        </td>
                        <td>
                            <?php echo($name); ?>
                        </td>
                        <td>
                            <?php echo($address_1); ?>
                        </td>
                        <td>
                            <?php echo($address_2); ?>
                        </td>
                        <td>
                            <?php echo($city); ?>
                        </td>
                        <td>
                            <?php echo($state); ?>
                        </td>
                        <td>
                            <?php echo($zip); ?>
                        </td>
                        <td>
                            <?php echo($phone); ?>
                        </td>
                    </tr>

                    <?php
                
}
            include(
'includes/close-db.php');    //====== close dB
        
?>

    </table>

    <hr>

    <!--- remove code below this line ------ -->

    <p>
        The following are the three files you will need to complete these assignments.

        Place these files in the 'examples' directory within your 'includes' directory.

        -- or --

        Place them wherever you want, but then you must keep track of the paths.
    </p>

    <p class="red bold">
        Additionally, as said in class many times, DO NOT INCLUDE THESE FILES in your listing.
        It should be obvious that exposing the config file (containing user_id and password) would
        provide access to people outside this class!
    </p>
    <p>
        These files are:
    </p>

    <ol class="pad5">
        <li>
            config.php (configuration file)
        </li>
        <li>
            open-db.php (open db file)
        </li>
        <li>
            close.db (close db file)
        </li>
    </ol>

    <!--- remove code above this line ------ -->

<?php

    
//--- remove code below this line ------
    // DO NOT DISPLAY BELOW FILES!!!!!!!

    
echo('<hr>');

    
highlight_file('includes/config1.php');

    echo(
'<hr>');
    
highlight_file('includes/open-db.php');

    echo(
'<hr>');
    
highlight_file('includes/close-db.php');

    
// DO NOT DISPLAY ABOVE FILES!!!!!!!
    //--- remove code above this line ------

    
include('includes/footer.php');
?>