Hi all,
I'm new to php. I have a mysql table which contain 3 tables of content
table 1
id type execution_date executor established project_title tab_content
table 2
id type execution_date executor established project_title ins_consult
table 3
id type execution_date executor established project_title forum_cons
i want to display them in a spreadsheet (.xls) with some conditions.
Conditions are:
#select all table or individual table to display result
#select all field from all table
#select some fields from all table or single table
i have implement some issue
$DB_Server = "localhost"; //your MySQL Server
$DB_Username = "root"; //your MySQL User Name
$DB_Password = ""; //your MySQL Password
$DB_DBName = "icddrb"; //your MySQL Database Name
$search_from_date = $_POST['start_date'];
$search_to_date = $_POST['end_date'];
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
$now_date = date('m-d-Y H:i');
if(($_POST['typer_of_report'] == 'rrc_report') || ($_POST['typer_of_report'] == 'all_report'))
{
$DB_TBLName = 'rrc_record';
}
if(($_POST['typer_of_report'] == 'erc_report') || ($_POST['typer_of_report'] == 'all_report'))
{
$DB_TBLName2 = 'erc_record';
}
if(($_POST['typer_of_report'] == 'aeec_report') || ($_POST['typer_of_report'] == 'all_report'))
{
$DB_TBLName3 = 'aeec_record';
}
$file_type = "vnd.ms-excel";
$file_ending = "xls";
//}
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=protocol_report.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
if($DB_TBLName)
{
$sql = "Select * from ".$DB_TBLName." where execution_date >= '".$search_from_date."' and
execution_date <= '".$search_to_date."' order by execution_date desc";
$Use_Title = 1;
$title = "Report for $DB_TBLName on $now_date";
$result = @mysql_query($sql,$Connect)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
if ($Use_Title == 1)
{
echo("$title\n");
}
$sep = "\t"; //tabbed character
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
//}
}