Cheryl Lander
asked on
mysql to excel question
I'm exporting info from a mysql db to excel. All works fine.
Is there anyway of adding to the script something which will add three fields/cells to excel which arent part of the db.
for example
add a excel heading of 'sample' and a cell value of 'X' to each record.
See script below.
<?
$check = mysql_pconnect("sample", "sample", "sample") or die(mysql_error());
mysql_select_db("sample", $check) or die(mysql_error());
$Recordset1 = mysql_query("SELECT date, subtotal as Amount, total as IncTax Amount, companyname as Cofusedmedia, description FROM tblinvoices t1, tblclients t2, tblinvoiceitems t3
where t1.userid = t2.id
and t1.userid = t3.userid", $check) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records et1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1 );
$fields = mysql_num_fields($Recordse t1);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($Recordse t1, $i) . "\t";
}
do {
$line = '';
foreach($row_Recordset1 as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
} while($row_Recordset1 = mysql_fetch_assoc($Records et1));
$data = str_replace("\r","",$data) ;
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream") ;
header("Content-Dispositio n: attachment; filename=report.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
<?php
mysql_free_result($Records et1);
?>
Is there anyway of adding to the script something which will add three fields/cells to excel which arent part of the db.
for example
add a excel heading of 'sample' and a cell value of 'X' to each record.
See script below.
<?
$check = mysql_pconnect("sample", "sample", "sample") or die(mysql_error());
mysql_select_db("sample", $check) or die(mysql_error());
$Recordset1 = mysql_query("SELECT date, subtotal as Amount, total as IncTax Amount, companyname as Cofusedmedia, description FROM tblinvoices t1, tblclients t2, tblinvoiceitems t3
where t1.userid = t2.id
and t1.userid = t3.userid", $check) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Records
$totalRows_Recordset1 = mysql_num_rows($Recordset1
$fields = mysql_num_fields($Recordse
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($Recordse
}
do {
$line = '';
foreach($row_Recordset1 as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
} while($row_Recordset1 = mysql_fetch_assoc($Records
$data = str_replace("\r","",$data)
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream")
header("Content-Dispositio
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
<?php
mysql_free_result($Records
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.