Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("__header.php");
- echo <<<end
- <table class="table table-striped">
- <thead>
- <tr>
- <th>Username</th><th>Joined On</th><th>Group(s)</th>
- </tr>
- </thead>
- <tbody>
- end;
- // Pagination
- $record_start = 0;
- $record_limit = 10;
- $current_page = 1;
- if (isset($_GET["page"]) && is_numeric($_GET["page"]))
- $current_page = (int) $_GET["page"];
- if ($current_page < 1)
- $current_page = 1;
- $record_start = ($current_page-1) * $record_limit;
- // Get data from the database
- $db->query("
- SELECT
- users.username AS name,
- users.join_date,
- permissions.name AS perm_name
- FROM
- (SELECT id, username, join_date FROM users LIMIT $record_start,$record_limit) AS users
- INNER JOIN
- user_permission_matches
- ON
- user_permission_matches.user_id = users.id
- LEFT JOIN
- permissions
- ON
- permissions.id = user_permission_matches.permission_id
- ");
- // Display query output in a table
- $result = $db->results(true);
- $num_of_items = $db->count();
- $non_atomic_key = ["perm_name"];
- $non_atomic_val = [];
- $user_count = 0;
- foreach ($non_atomic_key as $key)
- $non_atomic_val[$key] = [];
- for ($i=0; $i<$num_of_items; $i++) {
- $current_user = $result[$i]["name"];
- $next_user = "";
- if ($i < $num_of_items-1)
- $next_user = $result[$i+1]["name"];
- foreach ($non_atomic_key as $key)
- $non_atomic_val[$key][] = $result[$i][$key];
- if ($current_user != $next_user) {
- $user_count++;
- echo "<tr>";
- foreach ($result[$i] as $key=>$value) {
- if (in_array($key,$non_atomic_key))
- $value = implode(", ", $non_atomic_val[$key]);
- echo "<td>$value</td>";
- };
- echo "</tr>";
- foreach ($non_atomic_key as $key)
- $non_atomic_val[$key] = [];
- }
- }
- echo <<<end
- </tbody>
- </table>
- end;
- // Link to previous and next page
- if ($current_page > 1)
- echo "<BR /><A HREF=\"{$_SERVER[PHP_SELF]}?page=" . ($current_page-1) . "\">Prev</A>";
- if ($user_count == $record_limit)
- echo "<BR /><A HREF=\"{$_SERVER[PHP_SELF]}?page=" . ($current_page+1) . "\">Next</A>";
- include("__footer.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement