Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-14-2010, 07:13 PM [RESOLVED] MySQL export to CSV
Novice Talker

Posts: 9
Trades: 0
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 {
    
margin0;
    
padding0;
    
backgroundurl(images/img01.jpgrepeat-x left top;
    
font-familyArialHelveticasans-serif;
    
font-size12px;
    
color#66665E;
}

h1h2h3 {
    
margin0;
    
text-transformuppercase;
    
font-family"Trebuchet MS"Georgia"Times New Roman"Timesserif;
    
font-weightnormal;
    
color#0C95C9;
}

h1 font-size44px; }

h2 font-size18px; }

h3 { }

pulol {
    
margin-top0;
    
line-height240%;
    
text-alignjustify;
}

ulol { }

blockquote { }

color#0C95C9; }

a:hover text-decorationnone; }

a img {
    
bordernone;
}

inputtextareaselect {
 
background-color:#0498C8;
 
color:#ffffff;
 
border#000000 solid 1px;
}
img.left {
    
floatleft;
    
margin7px 30px 0 0;
}

img.right {
    
floatright;
    
margin7px 0 0 30px;
}

hr displaynone; }

.
list1 {
}

.
list1 li {
    
floatleft;
    
line-heightnormal;
}

.
list1 li img {
    
margin0 30px 30px 0;
}

.
list1 li.alt img {
    
margin-right0;
}

#wrapper {
}

/* Header */

#header-wrapper {
}

#header {
    
width920px;
    
height45px;
    
margin0 auto;
}

/* Menu */

#menu {
    
floatleft;
    
width540px;
    
height45px;
}

#menu ul {
    
margin0;
    
padding10px 0px 0px 5px;
    list-
stylenone;
    
line-heightnormal;
}

#menu li {
    
displayblock;
    
floatleft;
}

#menu a {
    
displayblock;
    
floatleft;
    
margin-right3px;
    
padding3px 25px 2px 25px;
    
text-decorationnone;
    
text-transformcapitalize;
    
font-familyArialHelveticasans-serif;
    
font-size12px;
    
color#FFFFFF;
}

#menu a:hover { text-decoration: underline; }

#menu .current_page_item a {
    
height20px;
    
background#FEC200 url(images/img02.jpg) repeat-x left top;
    
color#FFFFFF;
}

#menu .first {
    
backgroundnone;
}
/* Search */

#search {
    
floatright;
    
width305px;
    
height45px;
}

#search form {
    
floatright;
    
margin0;
    
padding12px 30px 0 0;
}

#search fieldset {
    
margin0;
    
padding0;
    
bordernone;
}

#search input {
    
floatleft;
    
font12px Georgia"Times New Roman"Timesserif;
    
bordernone;
}

#search-text {
    
width135px;
    
height18px;
    
padding3px 0 0 5px;
    
border1px solid #333333;
    
background#ECF9E4;
    
color#000000;
}

#search-submit {
    
height21px;
    
margin-left10px;
    
padding0px 5px;
    
background#000000;
    
color#FFFFFF;
}

/* Page */

#page {
    
width1024px;
    
margin0 auto;
}

#page-bgtop {
    
padding-top5px;
}

    
/** LOGO */

#logo {
    
width860px;
    
height134px;
    
margin0 auto;
    
backgroundurl(images/img04.jpgno-repeat right top;
}

#logo h1, #logo p {
    
margin0px;
    
line-heightnormal;
    
text-transformlowercase;
    
font-weightnormal;
    
color#FFFFFF;
}

#logo p {
    
text-transformlowercase;
    
font-size10px;
}

#logo h1 {
    
padding-top54px;
    
font-size34px;
}

#logo a {
    
text-decorationnone;
    
color#FFFFFF;
}

/* Content */

#content {
    
floatright;
    
width750px;
    
padding-top10px;
    
padding-right30px;
}

/* Post */

.post {
    
backgroundurl(images/img07.jpgrepeat-x left bottom;
    
margin-bottom25px;
}

.
post .title {
    
height30px;
    
color#549900;
}

.
post .title a {
    
text-decorationnone;
    
color#585D60;
}

.
post .date {
}

.
post .meta {
    
margin-top: -10px;
    
padding2px 30px 2px 16px;
    
backgroundurl(images/img03.gifno-repeat left 8px;
    
font-familyArialHelveticasans-serif;
    
font-weightnormal;
    
font-size10px;
    
color#66665E;
}

.
post .meta span {
    
displayblock;
    
margin-top: -10px;
}

.
post .meta a { }

.
post .entry {
    
padding10px 0;
}

.
post .links {
    
margin0 250px 0 0;
    
padding0 0 0 0px;
}

.
post .links .comments {
}

.
post .links .permalink {
    
padding-left17px;
}

/* Sidebar */

#sidebar {
    
floatleft;
    
width177px;
    
padding-left22px;
    
font-familyArialHelveticasans-serif;
    
font-size11px;
    
color#585D60;
}

#sidebar ul {
    
margin0;
    
padding0;
    list-
stylenone;
    
line-heightnormal;
}

#sidebar li {
    
margin-bottom30px;
    
padding0 0 10px 0px;
}

#sidebar li ul {
}

#sidebar li li {
    
margin0;
    
padding7px 10px 10px 7px;
    
backgroundurl(images/img07.jpgrepeat-x left bottom;
}

#sidebar p {
    
margin0;
    
padding0px 10px;
}

#sidebar h2 {
    
height26px;
    
margin0 0 10px 0px;
    
padding12px 0 2px 7px;
    
text-transformcapitalize;
    
font-size18px;
    
font-weightnormal;
    
color#464F54;
}


#sidebar p {
    
line-height200%;
}
#sidebar a {
    
text-alignleft;
    
text-decorationnone;
    
font-weightnormal;
    
color#585D60;
}

/* Calendar */

#calendar {
}

#calendar caption {
    
padding-bottom5px;
    
font-weightbold;
}

#calendar table {
    
width100%;
    
border-collapsecollapse;
    
border-bottom1px solid #24130F;
    
border-left1px solid #24130F;
    
border-right1px solid #24130F;
}

#calendar thead th {
    
padding5px 0;
    
text-aligncenter;
    
border-top1px solid #24130F;
    
border-left1px solid #24130F;
    
background#24130F;
}

#calendar tbody td {
    
padding5px 0;
    
text-aligncenter;
    
border-top1px solid #24130F;
    
border-left1px solid #24130F;
    
border-bottom1px solid #24130F;
}

#calendar tfoot td {
    
padding5px;
    
border-left1px solid #24130F;
    
border-bottom1px solid #24130F;
}

#calendar tfoot #next {
    
border-top1px solid #24130F;
    
text-alignright;
}

#calendar tfoot #prev {
    
border-top1px solid #24130F;
}

#calendar .pad {
    
border-bottom1px solid #24130F;
}

#calendar #today {
    
background#24130F;
}

/* Footer */

#footer {
    
width1024px;
    
height49px;
    
margin0 auto;
    
padding-top50px;
}

#footer-bgcontent {
    
margin0px;
    
padding0px;
    
height99px;
    
background#394144;
}

#footer p {
    
margin0;
    
text-aligncenter;
    
line-heightnormal;
    
text-transformuppercase;
    
font-size10px;
    
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> &middot; <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; 

Last edited by DrewDown; 05-14-2010 at 07:32 PM.. Reason: Issue Self Resolved
DrewDown is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-14-2010, 07:31 PM Re: MySQL export to CSV
Novice Talker

Posts: 9
Trades: 0
Ok, so here's the simple solution to this problem..

I was calling the export csv functions -- from inside of a page, that has html headers included in it.

I.E.

index.php
/functions/
/skins/
/settings/

I was using a header.tpl to be included inside of the header of my core system.
The core system is not needed to be included in the wrapper of the exportcsv.

So, I simply included my mysql config into the file, and moved the file to my main directory.

index.php
exportcsv.php
/functions/
/skins/
/settings/

-----

I believe this because of the headers or something, but the fix for the problem is too simply make it an independent file, and it produces properly.
DrewDown is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to MySQL export to CSV
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17365 seconds with 12 queries