Hello,
Posting for some small help.
I am using this code:
PHP Code:
<?php
$file = 'export';
$table = 'orders';
$csv_output = null;
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
This code is exporting to csv, but if you see at the bottom of the following code, I get my CSV export, but I don't need the HTML, etc at the top. Can anyone help me figure out how to get rid of ths.
PHP Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="robots" content="nofollow">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>EmpireBooks</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<style type='text/css'>
body {
margin: 0;
padding: 0;
background: url(images/img01.jpg) repeat-x left top;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #66665E;
}
h1, h2, h3 {
margin: 0;
text-transform: uppercase;
font-family: "Trebuchet MS", Georgia, "Times New Roman", Times, serif;
font-weight: normal;
color: #0C95C9;
}
h1 { font-size: 44px; }
h2 { font-size: 18px; }
h3 { }
p, ul, ol {
margin-top: 0;
line-height: 240%;
text-align: justify;
}
ul, ol { }
blockquote { }
a { color: #0C95C9; }
a:hover { text-decoration: none; }
a img {
border: none;
}
input, textarea, select {
background-color:#0498C8;
color:#ffffff;
border: #000000 solid 1px;
}
img.left {
float: left;
margin: 7px 30px 0 0;
}
img.right {
float: right;
margin: 7px 0 0 30px;
}
hr { display: none; }
.list1 {
}
.list1 li {
float: left;
line-height: normal;
}
.list1 li img {
margin: 0 30px 30px 0;
}
.list1 li.alt img {
margin-right: 0;
}
#wrapper {
}
/* Header */
#header-wrapper {
}
#header {
width: 920px;
height: 45px;
margin: 0 auto;
}
/* Menu */
#menu {
float: left;
width: 540px;
height: 45px;
}
#menu ul {
margin: 0;
padding: 10px 0px 0px 5px;
list-style: none;
line-height: normal;
}
#menu li {
display: block;
float: left;
}
#menu a {
display: block;
float: left;
margin-right: 3px;
padding: 3px 25px 2px 25px;
text-decoration: none;
text-transform: capitalize;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
}
#menu a:hover { text-decoration: underline; }
#menu .current_page_item a {
height: 20px;
background: #FEC200 url(images/img02.jpg) repeat-x left top;
color: #FFFFFF;
}
#menu .first {
background: none;
}
/* Search */
#search {
float: right;
width: 305px;
height: 45px;
}
#search form {
float: right;
margin: 0;
padding: 12px 30px 0 0;
}
#search fieldset {
margin: 0;
padding: 0;
border: none;
}
#search input {
float: left;
font: 12px Georgia, "Times New Roman", Times, serif;
border: none;
}
#search-text {
width: 135px;
height: 18px;
padding: 3px 0 0 5px;
border: 1px solid #333333;
background: #ECF9E4;
color: #000000;
}
#search-submit {
height: 21px;
margin-left: 10px;
padding: 0px 5px;
background: #000000;
color: #FFFFFF;
}
/* Page */
#page {
width: 1024px;
margin: 0 auto;
}
#page-bgtop {
padding-top: 5px;
}
/** LOGO */
#logo {
width: 860px;
height: 134px;
margin: 0 auto;
background: url(images/img04.jpg) no-repeat right top;
}
#logo h1, #logo p {
margin: 0px;
line-height: normal;
text-transform: lowercase;
font-weight: normal;
color: #FFFFFF;
}
#logo p {
text-transform: lowercase;
font-size: 10px;
}
#logo h1 {
padding-top: 54px;
font-size: 34px;
}
#logo a {
text-decoration: none;
color: #FFFFFF;
}
/* Content */
#content {
float: right;
width: 750px;
padding-top: 10px;
padding-right: 30px;
}
/* Post */
.post {
background: url(images/img07.jpg) repeat-x left bottom;
margin-bottom: 25px;
}
.post .title {
height: 30px;
color: #549900;
}
.post .title a {
text-decoration: none;
color: #585D60;
}
.post .date {
}
.post .meta {
margin-top: -10px;
padding: 2px 30px 2px 16px;
background: url(images/img03.gif) no-repeat left 8px;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 10px;
color: #66665E;
}
.post .meta span {
display: block;
margin-top: -10px;
}
.post .meta a { }
.post .entry {
padding: 10px 0;
}
.post .links {
margin: 0 250px 0 0;
padding: 0 0 0 0px;
}
.post .links .comments {
}
.post .links .permalink {
padding-left: 17px;
}
/* Sidebar */
#sidebar {
float: left;
width: 177px;
padding-left: 22px;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #585D60;
}
#sidebar ul {
margin: 0;
padding: 0;
list-style: none;
line-height: normal;
}
#sidebar li {
margin-bottom: 30px;
padding: 0 0 10px 0px;
}
#sidebar li ul {
}
#sidebar li li {
margin: 0;
padding: 7px 10px 10px 7px;
background: url(images/img07.jpg) repeat-x left bottom;
}
#sidebar p {
margin: 0;
padding: 0px 10px;
}
#sidebar h2 {
height: 26px;
margin: 0 0 10px 0px;
padding: 12px 0 2px 7px;
text-transform: capitalize;
font-size: 18px;
font-weight: normal;
color: #464F54;
}
#sidebar p {
line-height: 200%;
}
#sidebar a {
text-align: left;
text-decoration: none;
font-weight: normal;
color: #585D60;
}
/* Calendar */
#calendar {
}
#calendar caption {
padding-bottom: 5px;
font-weight: bold;
}
#calendar table {
width: 100%;
border-collapse: collapse;
border-bottom: 1px solid #24130F;
border-left: 1px solid #24130F;
border-right: 1px solid #24130F;
}
#calendar thead th {
padding: 5px 0;
text-align: center;
border-top: 1px solid #24130F;
border-left: 1px solid #24130F;
background: #24130F;
}
#calendar tbody td {
padding: 5px 0;
text-align: center;
border-top: 1px solid #24130F;
border-left: 1px solid #24130F;
border-bottom: 1px solid #24130F;
}
#calendar tfoot td {
padding: 5px;
border-left: 1px solid #24130F;
border-bottom: 1px solid #24130F;
}
#calendar tfoot #next {
border-top: 1px solid #24130F;
text-align: right;
}
#calendar tfoot #prev {
border-top: 1px solid #24130F;
}
#calendar .pad {
border-bottom: 1px solid #24130F;
}
#calendar #today {
background: #24130F;
}
/* Footer */
#footer {
width: 1024px;
height: 49px;
margin: 0 auto;
padding-top: 50px;
}
#footer-bgcontent {
margin: 0px;
padding: 0px;
height: 99px;
background: #394144;
}
#footer p {
margin: 0;
text-align: center;
line-height: normal;
text-transform: uppercase;
font-size: 10px;
color: #FFFFFF;
}
#footer a {
color: #E5FFC4;
</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=500,left = 400,top = 275');");
}
// End -->
</script>
<script type='text/javascript'>
function getCookie(Name){
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}
function setCookie(name, value, days){
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}
function rememberForm(formid){ //Main remember form values object
this.formref=document.getElementById(formid)? document.getElementById(formid) : document.forms[formid]
this.cookiename=formid
this.persistdays=180 //days to persist form values
this.fields=new Array()
this.cookiestr=""
var forminstance=this
rememberForm.dotask(this.formref, function(){forminstance.savevalues()}, "submit") //save form values onsubmit
rememberForm.dotask(window, function(){forminstance.recallvalues()}, "load") //populate form with saved values onload (body)
}
rememberForm.prototype.getfield=function(attr){ //get form field based on its ID or name attribute
var fieldref=document.getElementById(attr)? document.getElementById(attr) : this.formref[attr]
return fieldref
}
rememberForm.prototype.persistfields=function(){ //get form fields to persist values for
for (var i=0; i<arguments.length; i++){
this.fields[i]=this.getfield(arguments[i])
this.fields[i].fname=arguments[i] //store name or id of field in custom property
}
}
rememberForm.prototype.savevalues=function(){ //get form values and store in cookie
for (var i=0; i<this.fields.length; i++){
if (this.fields[i].type=="text")
this.cookiestr+=this.fields[i].fname+":"+escape(this.fields[i].value)+"#"
}
if (typeof this.togglebox!="undefined"){ //if "remember values checkbox" is defined
this.persistdays=(this.togglebox.checked)? this.persistdays : -1 //decide whether to save form values
this.cookiestr=(this.togglebox.checked)? this.cookiestr+"toggleboxid:on;" : this.cookiestr
}
else //if checkbox isn't defined, just remove final "#" from cookie string
this.cookiestr=this.cookiestr.substr(0, this.cookiestr.length-1)+";"
setCookie(this.cookiename, this.cookiestr, this.persistdays)
}
rememberForm.prototype.recallvalues=function(){ //populate form with saved values
var cookievalue=getCookie(this.cookiename)
if (cookievalue!=""){ //parse cookie, where cookie looks like: field1:value1#field2:value2...
var cookievaluepair=cookievalue.split("#")
for (var i=0; i<cookievaluepair.length; i++){
if (cookievaluepair[i].split(":")[0]!="toggleboxid" && this.getfield(cookievaluepair[i].split(":")[0]).type=="text")
this.getfield(cookievaluepair[i].split(":")[0]).value=unescape(cookievaluepair[i].split(":")[1])
else //else if name in name/value pair is "toggleboxid"
this.togglebox.checked=true
}
}
}
rememberForm.prototype.addtoggle=function(attr){
this.togglebox=this.getfield(attr)
}
//Call this function if you wish to clear the user's cookie of any saved values for this form instantly
rememberForm.prototype.clearcookie=function(){
setCookie(this.cookiename, "", -1)
}
rememberForm.dotask=function(target, functionref, tasktype){
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}
</script>
</head>
<body>
<div id="wrapper">
<div id="logo">
<h1><a href="#">EmpireBooks</a></h1>
<p><em>All Records Start Here</em></p>
</div>
<hr />
<!-- end #logo -->
<div id="header">
<div id="menu">
<ul>
<li><a href="./index.php" class="first">Home</a></li>
<li><a href="./index.php?p=entry">Entry</a></li>
<li><a href="./index.php?p=agtmgmnt">Agents</a></li>
<li><a href="./index.php?p=orders">Orders</a></li>
<li><a href="./index.php?p=hotel">Rent</a></li>
<li><a href="./index.php?p=export">Export</a></li>
</ul>
</div>
<!-- end #menu -->
<div id="search">
<form method="post" action="./index.php?p=orders&t=full">
<fieldset>
<input type="text" name="hidden_number" id="search-text" size="2" />
<input type="submit" name="submit" id="search-submit" value="QuickSearch" />
</fieldset>
</form>
</div>
<!-- end #search -->
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<div id="page">
<div id="page-bgtop">
<table width='100%' align='left'>
<tr>
<td align='left'>
Hello <b>Drew</b> · <a href="./index.php?p=system_notifications">System Notifications</a> | <a href="./index.php?p=login&sys=out">Logout</a> </td>
</tr>
</table>
<!-- end #content -->
<br /><br/><br /><br />
order_number; order_magazine; order_agent; order_date; order_comments; order_cash; order_check; order_front; order_mic; order_ph; order_gift; order_total; order_issues; order_subscriber; admin_comments; order_firstname; order_lastname; order_addressline1; order_addressline2; order_city; order_state; order_zipcode; order_email; order_phone; order_magcode1; order_years1; order_magcode2; order_years2; order_paymentamount; order_key; order_payment_times; order_errorcode; order_gender; order_cancelled;
55555; 5.0. MUSTANG & SUPER FORDS
; 5; 2010/07/06; ; 10; 28; 15; 15; 8; 0; 38; 12; Joe Schmoe; ; Joe Schmoe; Schmoe; 3658 County Rd. 550; Unit 5; Frankfort; MD; 4546; me@me.com; #########; 6; 4.14; 6; 8; 38; ws; 1; 0; male; 0;