I want to adapt this function that I use to export the complete DB to Excel to a function that by passing a parameter (paq) I returned an excel with the matches of the DB.
My HTML of the button.
<button onclick="Export()" class="btn btn-primary">Exportar a Excel</button>
Export function in JS.
function Export()
{
var conf = confirm("Exportar a CSV?");
if(conf == true)
{
window.open("pasajeros/export.php", '_blank');
}
}
And the export.php
<?php
require("ajax/db_connection2.php");
$query = "SELECT * FROM users";
if (!$result = mysqli_query($con, $query)) {
exit(mysqli_error($con));
}
$users = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$users[] = $row;
}
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=EMT_Pasajeros.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('ID', 'Nombre', 'Apellido', 'Email', 'F.Nacimiento', 'Telefono', 'Tel.Seguro', 'Paquete','$ VENTA', '$ EMISIÓN', '$ NETA', 'DNI', 'Vendedor', 'Link Comprobante'));
if (count($users) > 0) {
foreach ($users as $row) {
fputcsv($output, $row);
}
}
?>
I would like to know how to link the parameter of the Export ('parameter') of the onlick, with the function of JS and that this parameter is passed to the passengers / export.php so that it makes the query to the DB with the WHERE parameter.