Generate Excel Spreadsheets


I have a php program I use to generate an Excel Spreadsheet for download from a web server.

See attached.

My need now is to do 3 different spreadsheets.

Can I do this by putting a header("Location: next_prog.php") at the bottom of this first one, then the same at the 2nd?

Or can I just have a php program that has 3 includes, one for each program?


header("Content-type: application/");
$fn = "excel" . date('Y-m-d_h_i') . ".xls";
header("Content-Disposition: attachment; filename=" . $fn);
function conv_date($x) {
	$dt = substr($x,5,2) . "/" . substr($x,8,2) . "/" . substr($x,0,4);
	return $dt;
function date_conv($x) {
	$dt = substr($x,6,4) . "-" . substr($x,0,2) . "-" . substr($x,3,2);
	return $dt;
// connect database
include "db_connect.php";
if ($_SESSION['cid'] == "") {
	header("Location: index.php");
if ($_SESSION['uid'] == "" || $_SESSION['pwd'] == "") {
	header("Location: index.php");
if ($_SESSION['tout'] != 0) {
	$tdiff = time() - $_SESSION['alast_used'];
	if ($tdiff > $_SESSION['tout']) {
		header ("location: index.php");
if ($_SESSION['cid'] == 0 ) {
	$qry = "SELECT * from part order by pt_group, descr";
} else {	
	$qry = "SELECT * from cl_part where cid = " . $_SESSION['cid'] . " order by pt_group, descr";
$res = mysql_query ($qry, $Link);
$np = mysql_num_rows($res);
// header row
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
			margin: auto;
ul#nav {margin: 0 0 0 0px;}
ul {width:914px; margin:auto; font-family: "arial"; font-size:14px;}
ul.drop a { display:block; color: #fff; text-decoration: none;}
ul.drop, ul.drop li, ul.drop ul { list-style: none; margin: 0; padding: 0; background: #000; color: #fff;}
ul.drop { position: relative; z-index: 597; float: left; }
ul.drop li { float: left; line-height: 1.3em; vertical-align: middle; zoom: 1; padding: 05px 20px; }
ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; cursor: default; background: #f58023; }
ul.drop ul { visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 195px; background: #555; border: 1px solid #fff; }
ul.drop ul li { float: none; }
ul.drop ul ul { top: -2px; left: 100%; }
ul.drop li:hover > ul { visibility: visible }

.foot {width:914px;height:30px;background-color:#f58023;color:#fff;margin:5px 0px;text-align:center;padding:3px 0px; font-size: 10pt; font-family: Arial}
.pt10 {font-size: 10pt; font-family: Arial} 
.pt11 {font-size: 11pt; font-family: Arial} 
.pt11b {font-size: 11pt; font-weight:bold; font-family: Arial} 
.pt12 {font-size: 12pt; font-family: Arial} 
.pt14 {font-size: 14pt; font-family: Arial} 

#main{margin:5px 0px 0px 0px; }
<title>Service Tech Now - Parts Spreadsheet</title>
<table class="pt11b" border="1" width="1000">
		<td width="50" style="background-color: #FBB785;">&nbsp;</td>
		<td style="background-color: #FBB785;">Part Group</td>
		<td style="background-color: #FBB785;">Description</td>
		<td align="center" style="background-color: #FBB785;">Part No</td>
		<td align="center" style="background-color: #FBB785;">List Price</td>
<? for ($i = 0; $i < $np; $i++) {
	$p = mysql_fetch_array($res); ?>
		<td><? print $p['pt_group']; ?></td>
		<td><? print $p['descr']; ?></td>
		<td><? print $p['partno']; ?></td>
		<td>$<? print number_format($p['list'],2); ?></td>
<? } ?>	

Open in new window

(Edited to put the code into the code snippet ~Ray)
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
My suggestion would be to write the three spreadsheets into CSV files on the server and present the links to allow the client to download them.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.