Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Creating a connection to my database.
- // $host is my Pitt server.
- $host = "localhost";
- $user = "ggs6";
- $password = "";
- $dbname = "ggs6";
- $connect = mysqli_connect($host, $user, $password, $dbname);
- // Disconnect if there is an error.
- if(mysqli_connect_errno()){
- die("Database connection failed: ".
- mysqli_connect_error() .
- " (" . mysqli_connect_errno(). ")"
- );
- }
- ?>
- <html>
- <head>
- <title> Homework 7 </title>
- </head>
- <body>
- <?php
- // Get all the fields from the applicant table in the database.
- $query="SELECT * FROM applicant";
- $res = mysqli_query($connect, $query);
- // Make sure that the query did not fail.
- if(!$res) {
- die("Database query failed.");
- } else {
- ?>
- <!-- Create a applicants table that will store all the data from the db's applicant table-->
- <p>Applicants
- <table border="1">
- <thead>
- <tr>
- <th>Applicant ID</th>
- <th>First Name</th>
- <th>Last Name</th>
- <th>Date of Birth</th>
- <th>Education Level</th>
- <th>Citizenship Status</th>
- <th>Email</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // Use the mysqli_fetch_assoc() method to loop through each row, and get appropriate the field data
- // using the column names as keys to populate the table.
- while($row = mysqli_fetch_assoc($res) ){
- echo "<tr><td>".$row['idapplicant']."</td><td>".$row['fname']."</td><td>".$row['lname']."</td><td>".$row['dob']."</td>
- <td>".$row['education']."</td><td>".$row['citizen']."</td><td>".$row['email']."</td></tr>\n";
- }
- }
- ?>
- </tbody>
- </table>
- </p>
- <?php
- // Release the data that you got from first query.
- mysqli_free_result($res);
- ?>
- <?php
- // Do another query that will get all the data from address table.
- $query="SELECT * FROM address";
- $res = mysqli_query($connect, $query);
- // check that the query did not fail.
- if(!$res) {
- die("Database query failed.");
- } else {
- ?>
- <!--Create a html address table that will store all the data from the db's address table -->
- <p>Address
- <table border="1">
- <thead>
- <tr>
- <th>Applicant ID</th>
- <th>Street</th>
- <th>Apt</th>
- <th>City</th>
- <th>State</th>
- <th>Zip</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // Again loop through each row and use the column names as keys to get the values for each field.
- while($row = mysqli_fetch_assoc($res) ){
- echo "<tr><td>".$row['idApp']."</td><td>".$row['street']."</td><td>".$row['apt']."</td><td>".$row['city']."</td>
- <td>".$row['state']."</td><td>".$row['zip']."</td></tr>\n";
- }
- }
- ?>
- </tbody>
- </table>
- </p>
- <?php
- // Release the data that you got from second query.
- mysqli_free_result($res);
- ?>
- <?php
- // Do another query that will get all the data from pastEmp table.
- $query="SELECT * FROM pastEmp";
- $res = mysqli_query($connect, $query);
- // Check to see if query did not fail.
- if(!$res) {
- die("Database query failed.");
- } else {
- ?>
- <!-- Create a past employers table that will store all the data from the db's pastEmp table-->
- <p> Past Employers
- <table border="1">
- <thead>
- <tr>
- <th>Employer ID</th>
- <th>Employer Name</th>
- <th>Phone</th>
- <th>Supervisor</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // Again loop through each row and use the column names as keys to get the values for each field.
- while($row = mysqli_fetch_assoc($res) ){
- echo "<tr><td>".$row['idpastEmp']."</td><td>".$row['eName']."</td><td>".$row['ePhone']."</td><td>".$row['supervisor']."</td></tr>\n";
- }
- }
- ?>
- </tbody>
- </table>
- </p>
- <?php
- // Release the data that you got from last query.
- mysqli_free_result($res);
- ?>
- <?php
- // Do another query that will get all the data from appEmp table.
- $query="SELECT * FROM appEmp";
- $res = mysqli_query($connect, $query);
- // Check that the query did not fail and kill the connection if it did.
- if(!$res) {
- die("Database query failed.");
- } else {
- ?>
- <!-- Create a contacts table that will store all the data from the db's contact table-->
- <p> Contact
- <table border="1">
- <thead>
- <tr>
- <th>Employer ID</th>
- <th>Applicant ID</th>
- <th>Contact</th>
- </tr>
- </thead>
- <tbody>
- <?php
- // Loop through each row and use the column names as keys to get the values for each field.
- while($row = mysqli_fetch_assoc($res) ){
- echo "<tr><td>".$row['idEmp']."</td><td>".$row['idApp']."</td><td>".$row['contact']."</td></tr>\n";
- }
- }
- ?>
- </tbody>
- </table>
- </p>
- <?php
- // Release the data that you got from last query.
- mysqli_free_result($res);
- ?>
- <?php
- // Close the db connection.
- mysqli_close($connect);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement