PHP代码在2页而不是1页上打印

时间:2019-03-22 11:05:19

标签: php mysql

我已经在php上构建了POS系统,并面临一个非常有趣的问题。我可以在销售通知单上添加多达20个项目,并将其存储在数据库中,我们可以检索并打印它,但是每当我打印它时,它总会出现在2页而不是一页中,即使有一件,其余的值是null。有没有办法强制在一页上打印?

代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Print Invoice - Chara Motor Servicing</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css" />

    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
<div class="container">
    <div class="row">
        <div class="col-xs-12">
            <div class="text-center">

                <h3>Chara Motor Servicing</h3>
                <h4>Address Line 1</h4>
                <h4>Telephone: 000000000000</h4>
                <h4>GSTIN: XXXXXXXXXXXXXXX</h4>
            </div>
            <hr>
<?php
    include 'database_connection.php';
    $data=$_GET['invoice_id'];
    $user_id=$data;

    $sql = "SELECT `name`, `phone`, `town`, `date`, `item1`, `item2`, `item3`, `item4`, `item5`, `item6`, `item7`, `item8`,`item9`, `item10`, `item11`, `item12`, `item13`, `item14`, `item15`, `item16`,`item17`, `item18`, `item19`, `item20`, `item21`, `item22`, `q1`, `q2`, `q3`, `q4`, `q5`, `q6`, `q7`, `q8`,`q9`, `q10`, `q11`, `q12`, `q13`, `q14`, `q15`, `q16`,`q17`, `q18`, `q19`, `q20`, `q21`, `q22`, `taxper`, `amt1`, `amt2`, `amt3`, `amt4`, `amt5`, `amt6`, `amt7`, `amt8`, `amt9`, `amt10`, `amt11`, `amt12`, `amt13`, `amt14`, `amt15`, `amt16`,`amt17`, `amt18`, `amt19`, `amt20`, `amt21`, `amt22`,`taxtotal`, `subtotal`, `status` FROM `sales` WHERE id=$user_id";
    $result = $conn->query($sql);

    while ($row = mysqli_fetch_array($result)):
        ?>
            <div class="row">

                <div class="col-xs-12 col-md-3 col-lg-3 pull-left">
                    <div class="panel panel-default height">
                        <div class="panel-heading">Invoiced To: </div>
                        <div class="panel-body">
                            <strong><?php echo $row['name']; ?></strong><br>
                            <?php echo $row['phone']; ?><br>
                            <?php echo $row['town']; ?><br>
                            <?php echo $row['date']; ?><br>
                            <strong>Invoice#: <?php echo $user_id; ?><br> </strong>
                            <strong><?php echo $row['status']; ?><br> </strong><br>
                            <button class="btn btn-primary hidden-print" onclick="myFunction()"><span class="glyphicon glyphicon-print" aria-hidden="true"></span> Print</button>
                        </div>
                    </div>
                </div>

            </div>

        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="text-center"><strong>Order Summary</strong></h3>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-condensed">
                            <thead>
                                <tr>
                                    <td><strong>Item Name</strong></td>
                                    <td class="text-center"><strong>Item Quantity</strong></td>
                                    <td class="text-right"><strong>Total Price</strong></td>
                                </tr>
                            </thead>
                            <tbody>

                                <tr>
                                    <td><?php echo $row['item1']; ?></td>
                                    <td class="text-center"><?php echo $row['q1']; ?></td>
                                    <td class="text-right"><?php echo $row['amt1']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item2']; ?></td>
                                    <td class="text-center"><?php echo $row['q2']; ?></td>
                                    <td class="text-right"><?php echo $row['amt2']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item3']; ?></td>
                                    <td class="text-center"><?php echo $row['q3']; ?></td>
                                    <td class="text-right"><?php echo $row['amt3']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item4']; ?></td>
                                    <td class="text-center"><?php echo $row['q4']; ?></td>
                                    <td class="text-right"><?php echo $row['amt4']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item5']; ?></td>
                                    <td class="text-center"><?php echo $row['q5']; ?></td>
                                    <td class="text-right"><?php echo $row['amt5']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item6']; ?></td>
                                    <td class="text-center"><?php echo $row['q6']; ?></td>
                                    <td class="text-right"><?php echo $row['amt6']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item7']; ?></td>
                                    <td class="text-center"><?php echo $row['q7']; ?></td>
                                    <td class="text-right"><?php echo $row['amt7']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item8']; ?></td>
                                    <td class="text-center"><?php echo $row['q8']; ?></td>
                                    <td class="text-right"><?php echo $row['amt8']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item9']; ?></td>
                                    <td class="text-center"><?php echo $row['q9']; ?></td>
                                    <td class="text-right"><?php echo $row['amt9']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item10']; ?></td>
                                    <td class="text-center"><?php echo $row['q10']; ?></td>
                                    <td class="text-right"><?php echo $row['amt10']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item11']; ?></td>
                                    <td class="text-center"><?php echo $row['q11']; ?></td>
                                    <td class="text-right"><?php echo $row['amt11']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item12']; ?></td>
                                    <td class="text-center"><?php echo $row['q12']; ?></td>
                                    <td class="text-right"><?php echo $row['amt12']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item13']; ?></td>
                                    <td class="text-center"><?php echo $row['q13']; ?></td>
                                    <td class="text-right"><?php echo $row['amt13']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item14']; ?></td>
                                    <td class="text-center"><?php echo $row['q14']; ?></td>
                                    <td class="text-right"><?php echo $row['amt14']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item15']; ?></td>
                                    <td class="text-center"><?php echo $row['q15']; ?></td>
                                    <td class="text-right"><?php echo $row['amt15']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item16']; ?></td>
                                    <td class="text-center"><?php echo $row['q16']; ?></td>
                                    <td class="text-right"><?php echo $row['amt16']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item17']; ?></td>
                                    <td class="text-center"><?php echo $row['q17']; ?></td>
                                    <td class="text-right"><?php echo $row['amt17']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item18']; ?></td>
                                    <td class="text-center"><?php echo $row['q18']; ?></td>
                                    <td class="text-right"><?php echo $row['amt18']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item19']; ?></td>
                                    <td class="text-center"><?php echo $row['q19']; ?></td>
                                    <td class="text-right"><?php echo $row['amt19']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item20']; ?></td>
                                    <td class="text-center"><?php echo $row['q20']; ?></td>
                                    <td class="text-right"><?php echo $row['amt20']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item21']; ?></td>
                                    <td class="text-center"><?php echo $row['q21']; ?></td>
                                    <td class="text-right"><?php echo $row['amt21']; ?></td>
                                </tr>

                                <tr>
                                    <td><?php echo $row['item22']; ?></td>
                                    <td class="text-center"><?php echo $row['q22']; ?></td>
                                    <td class="text-right"><?php echo $row['amt22']; ?></td>
                                </tr>


                                <tr>
                                    <td class="highrow"></td>
                                    <td class="highrow"></td>
                                    <td class="highrow text-center"><strong>GST/Tax (%)</strong></td>
                                    <td class="highrow text-right"><?php echo $row['taxper']; ?></td>
                                </tr>
                                <tr>
                                    <td class="emptyrow"></td>
                                    <td class="emptyrow"></td>
                                    <td class="emptyrow text-center"><strong>GST/Tax Amount</strong></td>
                                    <td class="emptyrow text-right"><?php echo $row['taxtotal']; ?></td>
                                </tr>
                                <tr>

                                    <td class="emptyrow"></td>
                                    <td class="emptyrow text-center"><strong>SubTotal</strong></td>
                                    <td class="emptyrow text-right"><strong><?php echo $row['subtotal']; ?></strong></td>

                                </tr>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php endwhile; ?>

<script>
function myFunction() {
    window.print();
}
</script>

<style>
.height {
    min-height: 200px;
}

.icon {
    font-size: 47px;
    color: #5CB85C;
}

.iconbig {
    font-size: 77px;
    color: #5CB85C;
}

.table > tbody > tr > .emptyrow {
    border-top: none;
}

.table > thead > tr > .emptyrow {
    border-bottom: none;
}

.table > tbody > tr > .highrow {
    border-top: 3px solid;
}
</style>
</div>
</body>
</html>

0 个答案:

没有答案