![]() |
|
||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||
|
|
#1 |
|
WLC Lover
Join Date: Oct 2010
Posts: 94
|
Hi,
Just want to ask on how can i export html table into a CSV file. I have tried this code but the html code is printed too. Code:
<?php
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=export.csv");
?>
http://www.kunalbabre.com/projects/table2CSV.php but prompts to save the file. |
|
|
|
|
|
#2 |
|
WLC Mod
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
|
Just make sure the PHP is only passed the tabular data, and not the rest of the HTML
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum. |
|
|
|
|
|
#3 |
|
WLC Lover
Join Date: Oct 2010
Posts: 94
|
I don't get it, here is my code:
Code:
<?php
$connect = mysql_connect("localhost","root","");
mysql_select_db("phptest",$connect);
$result = mysql_query("SELECT * FROM sales");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check Page</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
<script>
$(document).ready(function()
{
$("#myTable").tablesorter();
}
);
</script>
<style>
#container {
width:1276px;
margin: 0 auto;
}
#myTable td {
padding:0 10px;
border: 1px solid #09F;
}
#myTable th {
font-size:16px;
padding: 5px 0;
}
</style>
</head>
<body>
<div id="container">
<table id="myTable" cellpadding="0" class="tablesorter">
<thead bgcolor="#CCCCCC">
<tr>
<th>Contact</th>
<th>City</th>
<th>Company</th>
<th>State</th>
<th>Zip</th>
<th>TimeStamp</th>
<th>Status</th>
<th>Close Date</th>
<th>Units</th>
<th>Price</th>
<th>Group</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['contact'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['zip'] . "</td>";
echo "<td>" . $row['timestamp'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['closedate'] . "</td>";
echo "<td>" . $row['units'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['grouping'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
<?php
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=export.csv");
?>
</body>
</html>
|
|
|
|
|
|
#4 |
|
WLC Mod
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
|
Well, I don't know how the jQuery works, but I do know that the header has to be the first part of the PHP. You should be getting an error on that page.
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
Linear Mode |
|
|