query($tableCheckQuery)->num_rows > 0; if ($tableExists) { // Get student data structure $columnsQuery = "SHOW COLUMNS FROM students_info"; $columnsResult = $conn->query($columnsQuery); $studentIdField = null; $studentNameFields = []; // Find student ID and name fields while ($column = $columnsResult->fetch_assoc()) { if (preg_match('/(student|stud|roll)[\s_-]?(id|number|no)/i', $column['Field'])) { $studentIdField = $column['Field']; } if (preg_match('/(student|stud)[\s_-]?(name)/i', $column['Field']) || preg_match('/(first|last|full)[\s_-]?(name)/i', $column['Field'])) { $studentNameFields[] = $column['Field']; } } // Handle search if (isset($_GET['search']) && !empty($_GET['search'])) { $searchTerm = trim($_GET['search']); // Prepare search conditions $conditions = []; $params = []; $types = ''; // Search by ID if ($studentIdField) { $conditions[] = "$studentIdField LIKE ?"; $params[] = "%$searchTerm%"; $types .= 's'; } // Search by name fields foreach ($studentNameFields as $field) { $conditions[] = "$field LIKE ?"; $params[] = "%$searchTerm%"; $types .= 's'; } if (!empty($conditions)) { $sql = "SELECT * FROM students_info WHERE " . implode(' OR ', $conditions); $stmt = $conn->prepare($sql); if (!empty($params)) { $stmt->bind_param($types, ...$params); } $stmt->execute(); $result = $stmt->get_result(); if ($result) { while ($row = $result->fetch_assoc()) { $students[] = $row; } } else { $error = "Error executing search query: " . $conn->error; } } else { $error = "No suitable fields found for searching."; } } else { // Get all students if no search $sql = "SELECT * FROM students_info"; $result = $conn->query($sql); if ($result) { while ($row = $result->fetch_assoc()) { $students[] = $row; } } else { $error = "Error fetching students: " . $conn->error; } } } else { $error = "Student information table not found in the database."; } // Include header include 'includes/header.php'; ?>

Students Information

View and search for student details

Students List
0): ?>
$value): ?> $value): ?>
Actions
View Projects
No students found.
close(); ?>