-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_members.php
76 lines (63 loc) · 1.83 KB
/
view_members.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html>
<head>
<link rel="stylesheet" href="style.css"></link>
</head>
<body>
<h4>List of all members:</h4>
<?php
$host = 'localhost';
$dbname = 'library-database';
$username = 'root';
$password = '';
//$password = 'Password1';
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT memberID, name, email, phone_num FROM member";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo '<table>
<tr>
<td> MemberID </td>
<td> Name </td>
<td> E-mail </td>
<td> Phone Number </td>
<td> Currently Borrowed Books </td>
</tr>';
while($row = $result->fetch_assoc()) {
//echo "MemberID: " . $row["memberID"]. "<br>Name: " . $row["name"]. "<br> E-mail: " . $row["email"]. "<br> Phone Number:" . $row["phone_num"]. "<br><br>";
echo '<tr>
<td>'.$row["memberID"].'</td>
<td>'.$row["name"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["phone_num"].'</td>
';
$memberid = $row["memberID"];
$books = "SELECT borrows.bookID, title FROM borrows, book_copy, book_info WHERE borrows.memberID = '$memberid' AND borrows.bookID = book_copy.bookID AND book_copy.ISBN = book_info.ISBN";
$book_res = $conn->query($books);
echo '<td>';
if ($book_res->num_rows == 0) {
echo 'N/A';
} else {
while($book_row = $book_res->fetch_assoc()) {
echo 'ID' . $book_row['bookID'] . ': ' . $book_row['title'] . '<br>';
}
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
} else {
echo "0 results";
}
$conn->close();
?>
<form action="index.php">
<input type="submit" value="Return Home" class="clickButton" />
</form>
</body>
</html>