dsbifvcxr458755493 2015-10-01 03:12
浏览 72
已采纳

如何制作打印报告的打印按钮?

I'm doing on a project but my problem is that i don't have any idea on how to make a print button to print my report..the report is in a table..can somebody please help me with this one?my question is how can i add a button for printing?

here is my code for the viewing of specific record

<?php
    include_once 'dbconfig.php';
    $username = isset($_GET['username']) ? $_GET['username'] : '';
    $password = isset($_GET['password']) ? $_GET['password'] : '';
    $province = isset($_GET['province']) ? $_GET['province'] : '';

    if(isset($_GET['user_id']))
    {
        $user_id = $_GET['user_id'];
        extract($crud->getID($user_id));
    }
?>

<body>
<div id="Survey-view">
    <div id="header">
    </div>

    <p><strong>INFORMATION</strong></p>
        <hr />
            <div id="main-frame">
                <table id="information-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Username</th>
                            <th>Password</th>
                            <th>Province</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $password; ?></td>
                            <td><?php echo $province; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div>
        <br />
    <br />
    <p><strong>ASP</strong></p>
        <hr />
            <div id="asp">
                <table id="asp-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Date Survey</th>
                            <th>Date Submitted</th>
                            <th>Date Approved</th>
                            <th>Date Recv'd by Region</th>
                            <th>Date Recv'd by DARPO</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div><!-- End of asp-->
        <br />
    <br />
    <p><strong>DENR/DARPO</strong></p>
        <hr />
            <div id="denrdarpo">
                <table id="denrdarpo-content" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Date Survey</th>
                            <th>Date Submitted</th>
                            <th>Date Approved</th>
                            <th>Date Recv'd by Region</th>
                            <th>Date Recv'd by DARPO</th>
                        </tr>
                    <tbody>
                        <tr>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                            <td><?php echo $username; ?></td>
                        </tr>
                    </tbody>
                    </thead>
                </table>
            </div><!--End of denrdarpo-->
        <br />
    <br />
    <p><strong>OTHERS</strong></p>
    <hr />
    <div id="others">
        <table id="others-content" cellspacing="0">
            <tr>
                <td>Project Number</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Module Number</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Fund Year</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>LAD Target</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Land Category</td>
                <td><select disabled>
                        <option><?php echo $username; ?></option>
                    </select></td>
                <td>LAnd Type</td>
                <td><select disabled>
                        <option><?php echo $username; ?></option>
                    </select></td>
            </tr>
            <tr>
                <td>Date Reported</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Date Suspended</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Date Completed</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Number of Lots</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Station</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Contractor</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
            <tr>
                <td>Agency</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
                <td>Cert 40</td>
                <td><input type="text" value="<?php echo $username; ?>" disabled></td>
            </tr>
        </table>
    </div>
</div>
</body>
  • 写回答

2条回答 默认 最新

  • donkey111111 2015-10-01 03:26
    关注

    Every time I need to do this I go to my old Gmail account, print a page and then view the source code cus I'm too lazy to remember the functions..

    This is how Google does it.

    <script type="text/javascript">// <![CDATA[
    document.body.onload=function(){document.body.offsetHeight;window.print()};
    // ]]></script>
    

    You could just as easily attach it to a button instead of doing it on load.

    <button onclick="document.body.offsetHeight;window.print();">Print</button>
    

    Here's a working example.

    And this one will remove the button from the printed page:

    <button onclick="this.style.display='none';document.body.offsetHeight;window.print();this.style.display='inline';">Print</button>
    

    And another example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)