我知道如何将 MySQL TABLE 导出为 Excel。但我的问题是我有一个复杂的场景,我可以从多个 MySQL 表中获取数据并将它们排列到 HTML 表输出中。我的问题是:如何将这些数据输出为 Excel?
这是我的代码
<?php
include(".../dbconnect.txt");
$result = mysql_query("select * from main_table where jobid='".$_GET['jobid']."'") or die(mysql_error());
?>
<table width='1450'>
<tr>
<td>S/N</td>
<td>Job Title</td>
<td>Applicant</td>
<td>Date</td>
<td>Expe</td>
<td>Course</td>
<td>Email</td>
<td>Quali</td>
<td>Age</td>
<td>Gender</td>
</tr>
<?php
$cnt =1;
while($row = mysql_fetch_array($result)){
$count = $cnt; $cnt++;
?>
<tr>
<td>
<?php echo $count; ?>
</td>
<td>
<?php
$re = mysql_query("select * from table1 where id='".$_GET['jobid']."'") or die(mysql_error());
$rw = mysql_fetch_array($re);
echo $rw['title'];
?>
</td>
<td>
<?php
$re1 = mysql_query("select * from table2 where email='".$row['email']."'") or die(mysql_error());
$rw1 = mysql_fetch_array($re1);
echo ucwords($rw1['fname']);
echo " ";
echo ucwords($rw1['lname']);
?>
</td>
<td><?php echo $row['date']; ?></td>
<td>
<?php
$re2 = mysql_query("select * from table3 where email='".$row['email']."'") or die(mysql_error());
$rw2 = mysql_fetch_array($re2);
echo $rw2['years'];
?>
</td>
<td>
<?php
$re3 = mysql_query("select * from table4 where email='".$row['email']."'") or die(mysql_error());
$rw3 = mysql_fetch_array($re3);
echo ucwords($rw3['course']);
?>
</td>
<td>
<?php echo $row['email']; ?>
</td>
<td>
<?php
echo $rw3['quali'];
?>
</td>
<td>
<?php echo $rw1['age']; ?>
</td>
<td>
<?php echo $rw1['gender']; ?>
</td>
</tr>
<?php } ?>
</table>
HTML 结果是这样的:
S/N Job Title Applicant Date Expe Course Email Quali Age Gender
1 Program Officer - Clinical Services Username Surname Wed 31, Jul, 2013 1 Agricultural Engineering useremail@yahoo.com BEng 24 Male
2 Program Officer - Clinical Services Username Surname Wed 31, Jul, 2013 3 Political Science useremail@gmail.com BSc 33 Male
3 Program Officer - Clinical Services Username Surname Wed 31, Jul, 2013 1 Microbiology useremail@yahoo.com HND 25 Female
如何在 Excel 中输出此表?