DANDARSMASH
Programmer
Hello all-
I'm trying to export to excel from a php mysql_query. It opens excel, but all i get is "  " in Cell A1.
With the export.php file:
And config.php
I'm trying to export to excel from a php mysql_query. It opens excel, but all i get is "  " in Cell A1.
PHP:
<?php
$str='select d.emailaddress, d.fullname, d.address, d.city, d.state, d.zip, d.makepayabletoname, d.makepayabletoaddress, d.makepayabletocity, d.makepayabletostate, d.makepayabletozip, p.filenumber, p.paymentstatus, p.paymentamount,p.paymentdate from payments p, dbase d where p.filenumber=d.filenumber and p.paymentstatus="PENDING" and p.paymentdate = "'.$date2.'"';
$arr=array('Payment Date','File Number','Payment Status','Payment Amount','E-mail Address','Full Name','Address','City','State','Zip','Payable Name','Payable Address','Payable City','Payable State','Payable Zip');
?>
<form action="export.php" method="post">
<input type="hidden" name="csv" value="yes" />
<input type="hidden" name="query" value="<? echo($str) ?>" />
<?
foreach ($arr as $key => $value)
{
echo '<input type="hidden" name="'.arr[$key].'" value="'.$value.'">\n';
}
?>
<input type="image" src="csv.jpg" width="35" height="35" />
</form>
With the export.php file:
PHP:
<?
include('config.php');// database connectivity code
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$fp = fopen('php://output', 'w');
fputcsv($fp, $_POST['arr']);
$query=stripslashes($_POST['query']);
$q1=mysql_query($query)or die(mysql_error());
while ($row1 = mysql_fetch_assoc($q1)) fputcsv($fp, $row1);
?>
And config.php
PHP:
<?php
// Connection's Parameters
$db_host="xxxxx";
$db_name="xxxxx";
$username="root";
$password="xxxxx";
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// Connection
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
?>