我有一个这样的表格:
<form method="post" action="track_reports.php" name="form">
<table id="mytable">
<tr>
<td>
<input type="checkbox" name="chkBadge" onClick="apply(this.checked, 'textBox')"> <font class="category">Badge ID</font>
</td>
<td>
<input id="textBox" class="text sign" type="text" name="badge_id" disabled="disabled">
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="chkEmp" onClick="apply(this.checked, 'textBox2')"> <font class="category">Employee Name</font>
</td>
<td>
<input id="textBox2" class="text sign" type="text" name="employee_name" disabled="disabled">
</td>
</tr>
<tr>
<td>
<input id="myCheckBox" type="checkbox" name="chkEmpOtDate" onClick="apply(this.checked, 'textBox3', 'textBox4')"> <font class="category">OT Date</font>
</td>
<td>
<font class="category">From</font> <input class="text sign" id="textBox3" type="text" name="alamat" disabled="disabled"> <font class="category">To</font> <input class="text sign" id="textBox4" type="text" name="alamat" disabled="disabled">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Submit" disabled>
</td>
</tr>
</table>
</form>
这是跟踪报告的来源:
<div id="bodyText" class="bodyText">
<div class="header">
<div class="content">
<h1>Report Submissions</h1>
</div>
</div>
<?php
include ("config.php");
$bagianWhere = "";
if (isset($_POST['chkBadge']))
{
$badge_id = $_POST['badge_id'];
if (empty($bagianWhere))
{
$bagianWhere .= "badge_id = '$badge_id'";
}
}
if (isset($_POST['chkEmp']))
{
$employee_name = $_POST['employee_name'];
if (empty($bagianWhere))
{
$bagianWhere .= "employee_name LIKE '$employee_name'";
}
else
{
$bagianWhere .= " AND employee_name LIKE '$employee_name'";
}
}
if (isset($_POST['chkOtdate']))
{
$ot_date = $_POST['ot_date'];
if (empty($bagianWhere))
{
$bagianWhere .= "ot_date LIKE '%$ot_date%'";
}
else
{
$bagianWhere .= " AND ot_date LIKE '%$ot_date%'";
}
}
$query = "SELECT * FROM t_submissions WHERE ".$bagianWhere;
$hasil = mysql_query($query);
echo "<table cellspacing='0'>";
echo "<tr><th class='th'>Badge ID</th><th class='th'>Employee Name</th><th class='th'>Department</th><th class='th'>OT Date</th></tr>";
while ($data = mysql_fetch_array($hasil))
{
echo "<tr><td class='td'>".$data['badge_id']."</td><td class='td'>".$data['employee_name']."</td><td class='td'>".$data['dept_name']."</td><td class='td'>".$data['ot_date']."</td></tr>";
}
echo "</table>";
?>
<br>
<a title="Export to PDF"><img src="images/pdf_files.png"></a>
<a title="Export to Excel"><img src="images/excel_file.png"></a>
<br><br>
<input type="button" VALUE="Back" onClick="history.go(-1);return true;">
</div>
当我尝试使用badgeid进行搜索时,数据会显示出来。 现在我的问题是如何将页面上显示的数据导出为PDF / excel?
答案 0 :(得分:1)
对于以其他文件格式编写,直接编写代码并不容易,有些库提供了简单的界面来完成这些工作。
fpdf是我用来转换为PDF demos and download here
的最佳库phpexcel也是一个非常好的库,可用于转换为excel,PDF和多种格式.. Download and demo here