-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_users.php
48 lines (32 loc) · 1.38 KB
/
view_users.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
<?php # Script 9.6 - view_users.php #2
// This script retrieves all the records from the users table.
$page_title = 'View the Current Users';
include ('includes/header.html');
// Page header:
echo '<h1>Registered Users</h1>';
require ('mysqli_connect.php'); // Connect to the db.
// Make the query:
$q = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC";
$r = @mysqli_query ($dbc, $q); // Run the query.
// Count the number of returned rows:
$num = mysqli_num_rows($r);
if ($num > 0) { // If it ran OK, display the records.
// Print how many users there are:
echo "<p>There are currently $num registered users.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Date Registered</b></td></tr>
';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['dr'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
mysqli_free_result ($r); // Free up the resources.
} else { // If no records were returned.
echo '<p class="error">There are currently no registered users.</p>';
}
mysqli_close($dbc); // Close the database connection.
include ('includes/footer.html');
?>