<?php
include "../include/config.php";
session_start();
if (isset($_SESSION['email'])){?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Smart Academy</title>

    <style>
      body{
        font-family: 'Nunito', sans-serif;
        background: #eceff4;
      }
 .content{
  height:100vh;
   padding: 10px;
   
 }
 .content{
  margin-left: 200px;
}
 
 table{
   border-top:5px solid #494E88;
 
 }
 .content{
  z-index: 900;
}
.scroll{
padding:10px;
overflow-x:scroll;
}

    </style>
</head>
<body   style="background:;">
  <?php include "../include/nav.php";?>
<div class="content">
    <br> <br> <br>
<?php
if(isset($_POST['search1'])){
    $class=$_POST['class'];
    $classsession=$_POST['classsession'];
    
}
// Assuming you have already established a database connection

// Execute the query
$query = "SELECT * FROM students WHERE class = '$class' AND classsession = '$classsection'";
$result = mysqli_query($conn, $query);

// Create a new Excel file
require_once 'export.php';
$excel = new PHPExcel();
$sheet = $excel->getActiveSheet();

// Add header row
$headerRow = array('studentid', 'studentname');  // Replace with actual column names
$sheet->fromArray($headerRow, NULL, 'A1');

// Add data rows
$rowNumber = 2;
while ($row = mysqli_fetch_assoc($result)) {
    $dataRow = array($row['studentid'], $row['studentname']);  // Replace 'column1', 'column2', 'column3' with your actual column names
    $sheet->fromArray($dataRow, NULL, 'A' . $rowNumber);
    $rowNumber++;
}

// Save the Excel file
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('DATA.xlsx');
?>

  
</div>
<script>
  
 
$(document).ready(function(){
    $('#myTable').dataTable();
});
  
</script>
 <br>
</body>
</html>
<?php
}else {
  header("location:index.php");
}
?>