Jump to content

to set field name header in excel


sangeetha

Recommended Posts

hi.can anyone help me in solving this problem. i got this code from one site. Here i want to display the field name as the header instead of displaying the field name that was in mysql database table but the values are from the table.I want to change only the header.The code that is have is

<?phpheader("Content-type: application/octet-stream");header("Content-Disposition: attachment; filename=ajareport1.xls");header("Pragma: no-cache");header("Expires: 0");$database	= 'test';include("dbconnect.inc.php");mysql_connect('localhost','root','');@mysql_select_db($database) or die("Unable to select database");$select = "SELECT * from studentid ";$export = mysql_query($select);$count = mysql_num_fields($export);$header='';$data='';// to display field name in excelfor ($i = 0; $i < $count; $i++) {$header .= mysql_field_name($export, $i)."\t";}while($row = mysql_fetch_row($export)) {$line = '';foreach($row as $value) {if ((!isset($value)) OR ($value == "")) {$value = "\t";} else {$value = str_replace('"', '""', $value);$value = '"' . $value . '"' . "\t";}$line .= $value;}$data .= trim($line)."\n";}$data = str_replace("\r", "", $data);if ($data == "") {$data = "\n(0) Records Found!\n";}print "$header\n$data";?>

where to do the change in the above code.Thanks in advance.

Link to comment
Share on other sites

for example, if the field names in the table are stud_id, sub,marks, den how to change those field names as student id, subject, marks for my purpose ?

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

But when executing the above code we get stud_id, sub,marks, which is the field names in the table.

Link to comment
Share on other sites

Right, because the code is telling it to get the field names in the table, so it makes sense that you're seeing the field names in the table. Can you just write them out yourself?$header="student id" . "\t" . "subject" . "\t" ....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...