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;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.