I have a PHP code to download one mysql table to excel sheet.what i want to do is download 2 tables in to same excel sheet.those tables are should be in different excel worksheet.please help me. this code work fine.it’s download one table.
[code=php]
<?php
ob_start();
session_start();
include(‘dbconnection.php’);
$usr= $_SESSION[‘fname’];
header(‘Content-Type: text/csv’);
header(‘Content-Disposition: attachment;filename=exported-data.csv’);
$select_table=mysql_query(“select * from regfarmer WHERE ffname=’$usr'”);
$rows = mysql_fetch_assoc($select_table);
if ($rows)
{
getcsv(array_keys($rows));
}
while($rows)
{
getcsv($rows);
$rows = mysql_fetch_assoc($select_table);
}
function getcsv($no_of_field_names)
{
$separate = ”;
foreach ($no_of_field_names as $field_name)
{
if (preg_match(‘/\r|\n|,|”/’, $field_name))
{
$field_name = ” . str_replace(”, $field_name) . ”;
}
echo $separate . $field_name;
$separate = ‘,’;
}
echo “rn”;
}
?>