Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将页面上显示的数据导出为pdf/excel?_Php_Mysql - Fatal编程技术网

Php 如何将页面上显示的数据导出为pdf/excel?

Php 如何将页面上显示的数据导出为pdf/excel?,php,mysql,Php,Mysql,我有一张这样的表格: <form method="post" action="track_reports.php" name="form"> <table id="mytable"> <tr> <td> <input type="chec

我有一张这样的表格:

<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>

徽章ID
员工姓名
加班日期
从到
这是跟踪报告的来源:

<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>

提交的报告

对于以其他文件格式编写代码来说,直接编写代码并不容易,有些库提供了简单的接口来完成这类工作

fpdf是我用来转换为PDF的最好的库

phpexcel也是一个非常好的库,可用于转换为excel、PDF和多种格式