JezK
Edit File: get_details.php
<?php // Database connection require_once 'db_connection.php'; // Function to fetch table schema function fetchTableSchema($tableName) { global $conn; $sql = "DESCRIBE $tableName"; $result = $conn->query($sql); $fields = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $fields[] = $row['Field']; } } return $fields; } if (isset($_POST['type'])) { $selectedType = $_POST['type']; // Define table name based on the selected type switch ($selectedType) { case 'grievance': $tableName = 'complaints'; break; case 'student': $tableName = 'studentcomplaint'; break; case 'teacher': $tableName = 'teacher_complaints'; break; default: echo "Invalid selection"; exit; } // Fetch table schema $fields = fetchTableSchema($tableName); // Print table header echo "<table border='1'>"; echo "<tr>"; foreach ($fields as $field) { echo "<th>$field</th>"; } echo "<th>Action</th>"; // Add Action column echo "</tr>"; // Print table data $sql = "SELECT * FROM $tableName ORDER BY `id` DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo "<tr>"; foreach ($fields as $field) { echo "<td>" . $row[$field] . "</td>"; } // Add Action buttons echo "<td><button onclick='openModal(" . $row['id'] . ", \"$selectedType\")'>View Questions</button></td>"; echo "</tr>"; } } else { echo "<tr><td colspan='" . (count($fields) + 1) . "'>No data available</td></tr>"; } echo "</table>"; // Modal for displaying questions echo "<div id='myModal' class='modal'>"; echo "<div class='modal-content'>"; echo "<span class='close' onclick='closeModal()'>×</span>"; echo "<div id='questionContent'></div>"; echo "</div>"; echo "</div>"; echo "<script> function openModal(id, type) { var modal = document.getElementById('myModal'); var span = document.getElementsByClassName('close')[0]; modal.style.display = 'block'; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById('questionContent').innerHTML = this.responseText; } }; xhttp.open('GET', 'get_questions.php?id=' + id + '&type=' + type, true); xhttp.send(); } function closeModal() { var modal = document.getElementById('myModal'); modal.style.display = 'none'; } </script>"; } else { echo "Selection not made"; } ?>