We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,628 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

exporting data from mysql into multiple excel sheet using php

Hi all,

Can anyone help me or give me an idea on how export data from mysql into multiple excel sheet using php? Below is the code I used to export data from mysql in a single excel sheet. thanks in advance

<?php
	
	$filename = 'filename.csv';

	include 'connection.php';
	
	$date = date("m/d/Y");

	header("Content-type: appilication/x-msexcel");
	header("Content-disposition: attachment; filename=".$filename);
	header("Pragma: no-cache");
	header("Expires: 2");

	$csv_output1='LINE'.",";
	$csv_output1.='SHIFT'.",";
	$csv_output1.='FUNCTION'.",";
	$csv_output1.='EMPLOYEE ID'.",";
	$csv_output1.='NAME'."\n";

	
	echo $csv_output1;
	
	$view=mysql_query("SELECT * FROM tbl_name where Date='$date'");
		
		while($result=mysql_fetch_array($view))
		{
			$a = $result['Line'];
			$b = $result['Shift'];
			$c = $result['Function'];
			$d = $result['EmpNo'];
			$e = $result['EmpName'];
					
			$csv_output=$a.",";
			$csv_output.=$b.",";
			$csv_output.=$c.",";
			$csv_output.=$d.",";
			$csv_output.=$e.",";

			echo $csv_output;
		}
		
		exit;
?>
2
Contributors
1
Reply
1 Month
Discussion Span
1 Year Ago
Last Updated
4
Views
lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
Skill Endorsements: 0

your problem is that your making a csv file. You cant have multiple table with that, it would need to by xls.

take a look at this class

http://www.phpclasses.org/package/644-PHP-Easy-way-to-stream-Mysql-sql-content-to-Excel-.html

whiteyoh
Posting Pro in Training
479 posts since Jun 2009
Reputation Points: 15
Solved Threads: 15
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0584 seconds using 2.65MB