I have 2 date input fields(startdate,endate) that a user can selected. Once selected, data will show that is registered between the 2 dates provided by the user in a table format. how can I export that data that is shown in the table to excel with a button click without third party plugins ?
code that I used :
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
startdate: <input type="date" name="from_date">
enddate: <input type="date" name="to_date">
<input type="submit" name="date" id="date">
</form>
<!--<div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<button type="submit" name="excel" value="excel" id='excel'> Export to excel</button>
</form>
</div> --->
<?php
require('settings.php');
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
if (isset($_POST["date"])) {
$startDate = date("Y-m-d", strtotime($_POST['from_date'])); // Y-m-d
$endDate = date("Y-m-d", strtotime($_POST['to_date'])); // something weird is happening with the dates random dates slip between date ranges
$sql = "SELECT distinct latestv.* from(
select distinct Werkomschrijving_nr from POH_GL4 where versie Between ? and ? ) changedw
left join
(select distinct Werkomschrijving_nr, max(versie) AS maxdate, omschrijving from POH_GL4
group by Werkomschrijving_nr,omschrijving) latestv on latestv.Werkomschrijving_nr = changedw.Werkomschrijving_nr";
$stmt = $db->prepare($sql);
$stmt->execute([$startDate, $endDate]);
$result = $stmt->fetchAll();
echo "<table>";
echo "<tr><th>nr werkomschrijving</th><th>Last change date </th><th>Omschrijving</th></tr>";
foreach ($result as $key => $row) {
echo "<tr>";
echo "<td>" . $row['Werkomschrijving_nr'] . "</td>";
echo "<td>" . $row['maxdate'] . "</td>";
echo "<td>" . $row['omschrijving'] . "</td>";
echo "</tr>";
}}