<?php    
    // Attempt to connect to the database
    $dbconn = mysqli_connect("localhost", "root", "", "gamerental");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit(); // if it doesnt connect error page
    }
 
 //Getting data from the customers part of the database
    $result = mysqli_query($dbconn, "SELECT * FROM customers");
	//Puts the data into the table
    $datatable = "<table id='customertable' class='table table-bordered table-striped' style='width:100%'>
            <thead>
            <tr>
                    
					<th>Title</th>					
                    <th>Forename</th>
                    <th>Surname</th>
                    <th>Address1</th>
                    <th>Address2</th>
					<th>Postcode</th>
					<th>Telephone</th>
					<th>Email</th>
					<th>DateOfBirth</th>
					<th>Gender</th>
            </tr>
            </thead>
            <tbody>";
 //Putting in the data into the table depending on the database column names
    while($row = mysqli_fetch_array($result))
       {
            $datatable.= "<tr>";
			$datatable.= "<td>" . $row['Title'] . "</td>";
            $datatable.= "<td>" . $row['Forename'] . "</td>";
            $datatable.= "<td>" . $row['Surname'] . "</td>";
            $datatable.= "<td>" . $row['Address1'] . "</td>";
            $datatable.= "<td>" . $row['Address2'] . "</td>";				
			$datatable.= "<td>" . $row['Postcode'] . "</td>";
			$datatable.= "<td>" . $row['Telephone'] . "</td>";	
			$datatable.= "<td>" . $row['Email'] . "</td>";	
			$datatable.= "<td>" . $row['DataOfBirth'] . "</td>";
			$datatable.= "<td>" . $row['Gender'] . "</td>";		
            $datatable.= "</tr>";
       }

    $datatable.= "</tbody></table>";

    //close connection
    mysqli_close($dbconn);
?>



<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="Assignment">
        <meta name="generator" content="Jekyll v3.8.5">
        <title>Customer</title>  

        <!-- include any relevant css/js files -->
        <?php include "../template/pageheader.php"; ?>

    </head>
    <body>
        <!-- include the top menu -->
        <?php include "../template/topmenu.php"; ?> 
        <!-- end top menu -->

        <div class="container-fluid">
            <div class="row">
                <!-- insert the side menu -->
                <?php include "../template/sidemenu1.php"; ?>	
                <!-- end side menu -->

                <!-- webpage content goes here -->
                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
                  <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h1">Customers</h1> 
                  </div>
				  
				  <!--displays the table -->
				  <?php echo $datatable ?>
				  
				  
				  
                </main>
            </div>
        </div>

        <!-- include any relevant js files -->
        <?php include "../template/pagefooter.php"; ?>

    </body>
</html>
