0

私のプロジェクトでは、バスの雇用に関する情報を含む手紙を印刷できる必要があります。私はあまり経験がないので、非常に単純な文字をWebページに配置し、各文字に印刷ボタンを設定して、印刷したいものを印刷できるようにすることを考えました。私はすべてをやったと思いますが、印刷を機能させることができません。ボタンは無意味なボタンのようです。私のJavaScriptコーディングは貧弱なので、この問題を解決する方法がよくわかりません。どんな助けでもありがたいです。PHPを使用してページの特定の部分をダウンロード/印刷する方法から多くのアイデアを取り入れましたが、この特定の問題があるため、それを見るだけでは特に役に立ちません。

<?php
include "connection.php";

$id = 0;
$result = mysql_query("SELECT cost, date, time, pickuplocation, destination,    numberofpeople, endtime, hireid, payment FROM hire WHERE information='letter'");

while ($row = mysql_fetch_array($result)) {
    $id = $id + 1;
    echo "<div id=" . $id . ">";
    echo "The Hurst and Hassocks Community Bus Association <br> 
            Invoice <BR> <BR>
            Thank you for hiring with the Association. <BR>
            The total cost for the hire is: &pound;" . $cost = $row['cost'] . "<BR><BR>
            Your details for the hire: <BR>
            Date: " . $date = $row['date'] . " <BR>
            Time: " . $time = $row['time'] . " <br>
            Pick up location: " . $pickuplocation = $row['pickuplocation'] . " <br>
            Destination: " . $destination = $row['destination'] . " <br>
            Number of people: " . $numberofpeople = $row['numberofpeople'] . " <br>
            End time: " . $endtime = $row['endtime'] . " <br>
            Hire ID: " . $hireid = $row['hireid'] . " <br><br>";

    if (($payment = $row['payment']) == "cheque") {
        echo "In order to pay for your hire and therefore confirm it, please address your     cheque to The Hurst and Hassocks Community Bus Association and include the total cost. Put your cheque in an envelope and send to the following address:  <BR><BR>";
    }

    if (($payment = $row['payment']) == "transfer") {
        echo "In order to pay for your hire and therefore confirm it, you will need to make an online bank transfer to The Hurst and Hassocks Community Bus Association. You will need to enter the Account Number and Sort Code when making the transfer. <BR>
            Account Number:  <BR>
            Sort Code: <BR><br>";
    }

    echo "We will need to receive payment at least 3 days before the date of the hire in order to confirm details with you. If payment is not received by then, the hire will be cancelled. Once payment is received we will send you a confirmation letter. Your driver for the hire will then contact you a few days before the hire to confirm details. <BR><br>
            Thank you for hiring with us, <br><br>

            Simon Strange, <br>
            The Hurst and Hassocks Community Bus Association<br><br><br>--------------------------------------------------------------<br><br>";
    echo "</div>";
    echo "<input type='button' value='Print' onclick='printPage(" . $id . ");'></input>";
    echo $id;

    echo "<br>--------------------------------------------------------------<br><br>";
}
?>

<script>
    function printPage('<?php $id; ?>') {

        var html='<html>';
        html+= document.getElementById(id).innerHTML;
        html+='</html>';
        var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status =0');
        printWin.document.write(html);
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();
    }
</script>
4

1 に答える 1

2

変更する必要があります:

function printPage('<?php $id; ?>') {

に:

function printPage(id) {

それを試してみませんか?

于 2013-02-24T18:35:37.817 に答える