Advertisement
eliza211

Untitled

May 1st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.         //get logged in username
  3.         $username = $_SESSION['username'];
  4.         //connect to the database
  5.         include ('connect.php');
  6.         $query = ("SELECT * FROM staff WHERE username ='$username'");
  7.             $result = mysqli_query($connect, $query);
  8.                 //fetch associative array
  9.                 while($row = mysqli_fetch_assoc($result)){
  10.                     //get staff id
  11.                     $id = $row['staff_id'];
  12.                     //Join staff and class tables o foreign key class_year and select all data based on the staff id
  13.                     $sql = "SELECT * FROM staff INNER JOIN class ON staff.class_year = class.class_year WHERE staff_id = '$id' ";
  14.                     $result = mysqli_query($connect, $sql);
  15.                     if ($result->num_rows > 0) {
  16.                             ?>
  17.                             <select name = "class_year">
  18.                                 <option selected="selected" disabled='disabled'>Please Select</option>
  19.                                 <?php
  20.                                 while($row1 = mysqli_fetch_array($result)) {
  21.                                     ?>
  22.                                     <option><?php echo $row1['class_year'];?></option>
  23.                                     <?php
  24.                                 }
  25.                             }
  26.                             ?>
  27.                         </select>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement