// Enable error reporting for debugging (remove or comment out in production)
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Check if admin is logged in
if (!isset($_SESSION['admin_id'])) {
header("Location: ../admin_login.php");
exit();
}
// Fetch prescriptions with patient and doctor names
stmt=pdo->prepare("
SELECT p.*, pat.name AS patient_name, doc.name AS doctor_name
FROM prescriptions p
LEFT JOIN patients pat ON p.patient_id = pat.id
LEFT JOIN doctors doc ON p.doctor_id = doc.id
ORDER BY p.date_prescribed DESC
");
stmt−>execute(prescriptions = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Fixed: Uncommented and included the latest version of jQuery from a CDN.
Reason: DataTables requires jQuery to function correctly.
html
<!-- Include jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
CSS Enhancements:
Removed Duplicate Font Imports: The @import statement was removed from the <style> tag since the font is already linked in the <head>.
Updated Class Names: Changed class names to be more descriptive and consistent by prefixing them with prescriptions-.
Improved Table Styling: Added zebra striping, hover effects, and padding to enhance readability.
Button Styling: Standardized button styles with consistent colors, padding, and hover effects.
Responsive Design: Ensured that the table and buttons adapt well on smaller screens.
Table Improvements:
Zebra Striping & Hover Effects: Enhances readability by alternating row colors and highlighting rows on hover.
Padding: Increased padding in table cells for better spacing.
Responsive Initialization: Enabled responsive behavior in DataTables for better usability on various devices.
Accessibility & Security:
URL Encoding: Used urlencode for id parameters in URLs to ensure safe transmission.
HTML Language Attribute: Added lang="en" to the <html> tag for better accessibility.
html
<html lang="en">
DataTables Initialization:
Language Customization: Changed default language settings to better fit the user interface.
Responsive Extension: Enabled the responsive extension for better table behavior on different screen sizes.
javascript
Additional Recommendations
Separate CSS File:
For better maintainability, consider moving the CSS into a separate .css file and linking it in the <head> section.
Optimizing Performance:
Minify CSS & JS: Minify your CSS and JS files to reduce load times.
Caching: Implement caching strategies for static assets.
Enhanced Security:
Prepared Statements: Ensure that all database interactions use prepared statements to prevent SQL injection.
CSRF Protection: Implement Cross-Site Request Forgery (CSRF) tokens for forms and actions that modify data.
User Feedback:
Notifications: Provide feedback to the admin upon successful addition, editing, or deletion of prescriptions.
Error Handling: Gracefully handle potential errors during data fetching or processing.
Pagination & Search Optimization:
Server-Side Processing: For large datasets, consider implementing server-side processing with DataTables to handle pagination, searching, and ordering more efficiently.
Accessibility:
ARIA Labels: Use ARIA attributes to improve accessibility for users with assistive technologies.
Keyboard Navigation: Ensure that all interactive elements are accessible via keyboard.
By implementing these changes and recommendations, your prescriptions list page will not only function correctly but also provide a better user experience for the admins managing the prescriptions.