CoolFace
Apppublic

Skullwanderer/cohort-manager

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
view_trainees.php93 linesDownload Raw Back to root
1```php2<?php3session_start();4 5// Check if user is logged in6if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {7    header("Location: login.php");8    exit;9}10// Database connection11$servername = "localhost";12$db_username = "root";13$db_password = "";14$dbname = "markpsystem";15 16$conn = new mysqli($servername, $db_username, $db_password, $dbname);17// Check connection18if ($conn->connect_error) {19    die("Connection failed: " . $conn->connect_error);20}21 22// Fetch all trainees with cohort information23$sql = "SELECT t.id, t.registration_number, t.first_name, t.last_name, t.email, t.phone, t.created_at, 24               c.cohort_name, c.intake_year 25        FROM trainees t 26        LEFT JOIN cohorts c ON t.cohort_id = c.id 27        ORDER BY t.created_at DESC";28$result = $conn->query($sql);29?>30 31<!DOCTYPE html>32<html lang="en">33<head>34    <meta charset="UTF-8">35    <meta name="viewport" content="width=device-width, initial-scale=1.0">36    <title>View Trainees</title>37</head>38<body>39    <h1>Trainees List</h1>40    41    <p><a href="add_trainee.php">Add New Trainee</a></p>42    43    <?php if ($result->num_rows > 0): ?>44        <table border="1" cellpadding="10" cellspacing="0">45            <thead>46                <tr>47                    <th>Registration Number</th>48                    <th>Name</th>49                    <th>Email</th>50                    <th>Phone</th>51                    <th>Cohort</th>52                    <th>Registered At</th>53                    <th>Actions</th>54                </tr>55            </thead>56            <tbody>57                <?php while($row = $result->fetch_assoc()): ?>58                    <tr>59                        <td><?php echo htmlspecialchars($row['registration_number']); ?></td>60                        <td><?php echo htmlspecialchars($row['first_name'] . " " . $row['last_name']); ?></td>61                        <td><?php echo htmlspecialchars($row['email']); ?></td>62                        <td><?php echo htmlspecialchars($row['phone']); ?></td>63                        <td>64                            <?php 65                            if ($row['cohort_name']) {66                                echo htmlspecialchars($row['cohort_name'] . " (" . $row['intake_year'] . ")");67                            } else {68                                echo "Not assigned";69                            }70                            ?>71                        </td>72                        <td><?php echo date('M j, Y g:i A', strtotime($row['created_at'])); ?></td>73                        <td>74                            <a href="#">Edit</a> | 75                            <a href="#">Delete</a>76                        </td>77                    </tr>78                <?php endwhile; ?>79            </tbody>80        </table>81    <?php else: ?>82        <div style="text-align: center; padding: 20px; color: #666;">83            <p>No trainees found. <a href="add_trainee.php">Add your first trainee</a>.</p>84        </div>85    <?php endif; ?>86    87    <?php $conn->close(); ?>88</body>89</html>90```91___METADATA_START___92{"repoId":"Skullwanderer/cohort-manager","isNew":false,"userName":"Skullwanderer"}93___METADATA_END___