Jazzy 1012
asked on
Download tables into separate sheets
I have a bunch of tables in one page, but here is an example code of two, the tables show when I click a button called "Generate report"
<?php
require "connection.php";
//error_reporting(E_ALL);
//ini_set('display_errors',1);
$date= date("m/d/Y");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css">
<style>
.container{
margin-top: 50px;
}
table, th,td {
border: 1px solid;
}
.panel-primary{
width:200%;
}
.table{
width: auto !important;
}
.panel-danger{
width: 60%;
}
.hbp{
width: 100% !important;
}
.rsvp{
width: 50% !important;
}
</style>
</head>
<body>
<title>Admin Reports</title>
<div class="container">
<h1 style= "padding-bottom:10px;">Daily Reports</h1>
<!-- BEGIN COLD -->
<div class="row">
<div class="panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Cold</h3>
</div>
<table class="table table-hover" id="dev-table">
<thead>
<tr>
<?php
$query = mysqli_query($conn,"SHOW columns FROM `call`");
// Loop over all result rows
while($row = mysqli_fetch_array($query))
{
if($row["Field"] == 'id')
{
continue;
}
echo '<th>';
echo $row["Field"];
echo '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
$query2= "SELECT * from `call` WHERE `Date` = '$date'";
$result= mysqli_query($conn, $query2);
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
foreach($row as $fieldname => $values)
{
if($fieldname == 'id')
{
continue;
}
else
{
echo '<td>';
echo $values;
echo '</td>';
}
}
echo '</tr>';
}
?>
</tbody>
</table>
<!-- END COLD -->
<!-- BEGIN COMM -->
<div class="panel-info">
<div class="panel-heading">
<h3 class="panel-title">Com</h3>
</div>
<table class="table table-hover" id="dev-table">
<thead>
<tr>
<?php
$query = mysqli_query($conn,"SHOW columns FROM `com`");
// Loop over all result rows
while($row = mysqli_fetch_array($query))
{
if($row["Field"] == 'id')
{
continue;
}
echo '<th>';
echo $row["Field"];
echo '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
$query2= "SELECT * from `com` WHERE `Date` = '$date'";
$result= mysqli_query($conn, $query2);
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
foreach($row as $fieldname => $values)
{
if($fieldname == 'id')
{
continue;
}
else
{
echo '<td>';
echo $values;
echo '</td>';
}
}
echo '</tr>';
}
?>
</tbody>
</table>
<!-- END COM -->
I want that instead of them displaying, when I click on "generate report" an excel file downloads with each table on a separate sheets? Is this possible?
ASKER
I'll be needing excel with different sheets, should I research for PHPExcel?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CSV files are almost universally associated with Excel, and do not require much "special" processing in PHP.
I expect that you could use something like PHPExcel to create a workbook with separate worksheets, but I have never tried that, so it would be a research project. If you can live with the CSV concept, instead of needing the Excel workbook, I can show you how to get it running immediately.