Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. <?php
  2. // Creating a connection to my database.
  3. // $host is my Pitt server.
  4. $host = "localhost";
  5. $user = "ggs6";
  6. $password = "";
  7. $dbname = "ggs6";
  8.  
  9. $connect = mysqli_connect($host, $user, $password, $dbname);
  10. // Disconnect if there is an error.
  11. if(mysqli_connect_errno()){
  12. die("Database connection failed: ".
  13. mysqli_connect_error() .
  14. " (" . mysqli_connect_errno(). ")"
  15. );
  16. }
  17. ?>
  18.  
  19. <html>
  20. <head>
  21. <title> Homework 7 </title>
  22. </head>
  23. <body>
  24.  
  25.  
  26. <?php
  27.  
  28. // Get all the fields from the applicant table in the database.
  29. $query="SELECT * FROM applicant";
  30. $res = mysqli_query($connect, $query);
  31.  
  32. // Make sure that the query did not fail.
  33. if(!$res) {
  34. die("Database query failed.");
  35. } else {
  36.  
  37. ?>
  38.  
  39. <!-- Create a applicants table that will store all the data from the db's applicant table-->
  40. <p>Applicants
  41. <table border="1">
  42. <thead>
  43. <tr>
  44. <th>Applicant ID</th>
  45. <th>First Name</th>
  46. <th>Last Name</th>
  47. <th>Date of Birth</th>
  48. <th>Education Level</th>
  49. <th>Citizenship Status</th>
  50. <th>Email</th>
  51. </tr>
  52. </thead>
  53. <tbody>
  54.  
  55. <?php
  56. // Use the mysqli_fetch_assoc() method to loop through each row, and get appropriate the field data
  57. // using the column names as keys to populate the table.
  58. while($row = mysqli_fetch_assoc($res) ){
  59. echo "<tr><td>".$row['idapplicant']."</td><td>".$row['fname']."</td><td>".$row['lname']."</td><td>".$row['dob']."</td>
  60. <td>".$row['education']."</td><td>".$row['citizen']."</td><td>".$row['email']."</td></tr>\n";
  61. }
  62. }
  63. ?>
  64. </tbody>
  65. </table>
  66. </p>
  67.  
  68. <?php
  69. // Release the data that you got from first query.
  70. mysqli_free_result($res);
  71. ?>
  72.  
  73. <?php
  74.  
  75. // Do another query that will get all the data from address table.
  76. $query="SELECT * FROM address";
  77. $res = mysqli_query($connect, $query);
  78.  
  79. // check that the query did not fail.
  80. if(!$res) {
  81. die("Database query failed.");
  82. } else {
  83.  
  84. ?>
  85.  
  86. <!--Create a html address table that will store all the data from the db's address table -->
  87. <p>Address
  88. <table border="1">
  89. <thead>
  90. <tr>
  91. <th>Applicant ID</th>
  92. <th>Street</th>
  93. <th>Apt</th>
  94. <th>City</th>
  95. <th>State</th>
  96. <th>Zip</th>
  97. </tr>
  98. </thead>
  99. <tbody>
  100. <?php
  101. // Again loop through each row and use the column names as keys to get the values for each field.
  102. while($row = mysqli_fetch_assoc($res) ){
  103. echo "<tr><td>".$row['idApp']."</td><td>".$row['street']."</td><td>".$row['apt']."</td><td>".$row['city']."</td>
  104. <td>".$row['state']."</td><td>".$row['zip']."</td></tr>\n";
  105. }
  106. }
  107. ?>
  108. </tbody>
  109. </table>
  110. </p>
  111.  
  112. <?php
  113. // Release the data that you got from second query.
  114. mysqli_free_result($res);
  115. ?>
  116.  
  117. <?php
  118.  
  119. // Do another query that will get all the data from pastEmp table.
  120. $query="SELECT * FROM pastEmp";
  121. $res = mysqli_query($connect, $query);
  122.  
  123. // Check to see if query did not fail.
  124. if(!$res) {
  125. die("Database query failed.");
  126. } else {
  127.  
  128. ?>
  129. <!-- Create a past employers table that will store all the data from the db's pastEmp table-->
  130. <p> Past Employers
  131. <table border="1">
  132. <thead>
  133. <tr>
  134. <th>Employer ID</th>
  135. <th>Employer Name</th>
  136. <th>Phone</th>
  137. <th>Supervisor</th>
  138. </tr>
  139. </thead>
  140. <tbody>
  141.  
  142. <?php
  143. // Again loop through each row and use the column names as keys to get the values for each field.
  144. while($row = mysqli_fetch_assoc($res) ){
  145. echo "<tr><td>".$row['idpastEmp']."</td><td>".$row['eName']."</td><td>".$row['ePhone']."</td><td>".$row['supervisor']."</td></tr>\n";
  146. }
  147. }
  148. ?>
  149. </tbody>
  150. </table>
  151. </p>
  152.  
  153. <?php
  154. // Release the data that you got from last query.
  155. mysqli_free_result($res);
  156. ?>
  157.  
  158. <?php
  159.  
  160. // Do another query that will get all the data from appEmp table.
  161. $query="SELECT * FROM appEmp";
  162. $res = mysqli_query($connect, $query);
  163.  
  164. // Check that the query did not fail and kill the connection if it did.
  165. if(!$res) {
  166. die("Database query failed.");
  167. } else {
  168.  
  169. ?>
  170.  
  171. <!-- Create a contacts table that will store all the data from the db's contact table-->
  172. <p> Contact
  173. <table border="1">
  174. <thead>
  175. <tr>
  176. <th>Employer ID</th>
  177. <th>Applicant ID</th>
  178. <th>Contact</th>
  179. </tr>
  180. </thead>
  181. <tbody>
  182. <?php
  183. // Loop through each row and use the column names as keys to get the values for each field.
  184. while($row = mysqli_fetch_assoc($res) ){
  185. echo "<tr><td>".$row['idEmp']."</td><td>".$row['idApp']."</td><td>".$row['contact']."</td></tr>\n";
  186. }
  187. }
  188. ?>
  189. </tbody>
  190. </table>
  191. </p>
  192.  
  193. <?php
  194. // Release the data that you got from last query.
  195. mysqli_free_result($res);
  196. ?>
  197.  
  198. <?php
  199.  
  200. // Close the db connection.
  201. mysqli_close($connect);
  202.  
  203. ?>
  204. </body>
  205. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement