Need Help to Get Output in Excel

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Need Help to Get Output in Excel

Post by manojsemwal1 »

hai iam using the below query to fetch data from database
when student submit the record that time CourseName is saved as CourseID like 1,2,3 as per courseName
While Fetching data form below query
$select = "select TempID,Name,FatherName,MotherName,DOB,Sex,Category,CourseName from Studentregdtb";.

Its print required data.i am export report in excel format.
i want to convert courseId to coursename from calling courseName tabel....

code are to get excel report .

$export = mysql_query($select) or die("Sql error : " . mysql_error());

$fields = mysql_num_fields($export);

for($i = 0; $i < $fields; $i++)
{
$header .= mysql_field_name($export , $i). "\t";
}

while($row = mysql_fetch_row($export))
{
$line = '';
foreach($row as $value)
{
if(!isset($value) || trim($value) == "")
{
$value = "\t";
}
else
{
// $value = str_replace('"' , '""' , $value);
$value = $value . "\t";
}
$line .= $value;
}
$data .= trim($line). "\n";
}
$data = str_replace("\r" , "" , $data);

if(trim($data) == "")
{
$data = "\n(0)Records Found!\n";
}
header("Content-type: application/ms-excel");
header("Content-Disposition: attachment; filename=StudentReport.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

Thanx
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: Need Help to Get Output in Excel

Post by manojsemwal1 »

Need Help send some suggestion ........................
Post Reply