2012-04-16 32 views
2

私は次のphpテーブルを持っていますが、私はどのようにphpテーブルに印刷機能を追加しますか?そして、クリックすると、次の表がプリンタで印刷され、私は 'CTRL + P'を試して、ヘッダー、フッター、ナビゲーションバーのページ例のhtmlセクトンしか得られず、結果のPHP結果は表示されません。プリンタで印刷機能付きphpテーブルを印刷

<?php 
echo "<table border='1' id= results> 
<tr> 
<th>FILEID</th> 
<th>Firstname</th> 
<th>Lastname</th> 
<th>Issue Date</th> 
<th>Interest Rate</th> 
<th>Terms</th> 
<th>Balance Outstanding</th> 
<th>Balance Outstanding</th> 
<th>New Loan</th> 
<th>Principal Repayment for $l_month</th> 
<th>Principal Repaid</th> 
<th>Balance Outstanding</th> 
<th>Interest Payment for $l_month </th> 
<th>INTEREST ACCUMULATED DURING FINNANCIAL YEAR</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
    { 


    echo "<tr>"; 

    echo "<td>" . $row['app_file_id'] . "</td>"; 
    echo"<td>". $row['app_fname']."</td>"; 
    echo"<td>". $row['app_lname']."</td>"; 
    echo"<td>". $row['commit_date'] ."</td>"; 
    echo"<td>". $row['computer_interest'] ."</td>"; 
    echo"<td>". $row['loan_life'] ."</td>"; 
    echo"<td>". $row['avg(app_ln_amnt)'] ."</td>"; 
    echo"<td>". $row['Balance Outstanding'] ."</td>"; 
    echo"<td>". $row['New Loan'] ."</td>"; 
    echo"<td>". $row['SUM(r.receipt_on_principal)'] ."</td>"; 
    echo"<td>". $row['Principal Repaid'] ."</td>"; 
    echo"<td>". $row['avg(app_amnt_owed)'] ."</td>";  
    echo"<td>". $row['SUM(r.receipt_on_interest)'] ."</td>"; 
    echo"<td>". $row['Interest Accumilated'] ."</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 
?> 
+1

これを印刷するためにどのアプリケーションを使用していますか?コード、または処理されたhtmlのみを印刷したいのですか? – James

+1

"私の文書のhtmlセクトンしか見つかりませんでした"とはどういう意味ですか?また、テーブル構造は無効なHTMLです。 – Flukey

+0

そのPHPコードのセクション私はテーブルから結果を印刷しようとしているが、私はすべてgettinはページのテンプレートであり、テンプレートはHTMLセクションの例、ナビゲーションバー、ヘッダーイメージフッタなど – dames

答えて

1

私はphpの新機能ですが、私がそれらの機能を実行することを知っている唯一の方法はjavascriptです。

以下は、印刷ボタンを表示してプリンタに送信するコードです.Google Chromeを使用すると、印刷プレビュー画面が最初に表示され、他のブラウザでは小さな印刷ウィンドウが開きます。あなたはフォーマットと非常に注意する必要がありますウェブサイトと

<SCRIPT LANGUAGE="JavaScript"> 
if (window.print) { 
document.write('<form><input type=button name=print value="Print Page"onClick="window.print()"></form>'); 
} 
</script> 

、HTTPは、印刷することが嫌いなので、ページ上の最小限のスクリプトを持っていることが最善である、そうでない場合はページの半分が間隔されます。特に、< ul>と< li>文のすべてを印刷するようなドロップダウンメニューのようなものを使用すると、ページの下の箇条書きの点に変換されます。それ以外の場合は、ページをPDFで表示することをお勧めします。ここでは、ページレイアウトをより詳細に制御できます。

0
<?php 
echo "<table border='1' id= results> 
<tr> 
<th>FILEID</th> 
<th>Firstname</th> 
<th>Lastname</th> 
<th>Issue Date</th> 
<th>Interest Rate</th> 
<th>Terms</th> 
<th>Balance Outstanding</th> 
<th>Balance Outstanding</th> 
<th>New Loan</th> 
<th>Principal Repayment for $l_month</th> 
<th>Principal Repaid</th> 
<th>Balance Outstanding</th> 
<th>Interest Payment for $l_month </th> 
<th>INTEREST ACCUMULATED DURING FINNANCIAL YEAR</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
    { 


    echo "<tr>"; 

    echo "<td>" . $row['app_file_id'] . "</td>"; 
    echo"<td>". $row['app_fname']."</td>"; 
    echo"<td>". $row['app_lname']."</td>"; 
    echo"<td>". $row['commit_date'] ."</td>"; 
    echo"<td>". $row['computer_interest'] ."</td>"; 
    echo"<td>". $row['loan_life'] ."</td>"; 
    echo"<td>". $row['avg(app_ln_amnt)'] ."</td>"; 
    echo"<td>". $row['Balance Outstanding'] ."</td>"; 
    echo"<td>". $row['New Loan'] ."</td>"; 
    echo"<td>". $row['SUM(r.receipt_on_principal)'] ."</td>"; 
    echo"<td>". $row['Principal Repaid'] ."</td>"; 
    echo"<td>". $row['avg(app_amnt_owed)'] ."</td>";  
    echo"<td>". $row['SUM(r.receipt_on_interest)'] ."</td>"; 
    echo"<td>". $row['Interest Accumilated'] ."</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 
?> 
<button onclick="javascript:window.print();"></button> 
+0

ありがとうございますが、印刷ボタンはどうですか? – dames

+0

はい、それはかなりクールなオプションの答えを更新しました –

0

私は最後に、このJavaScriptを追加したい:

<script type="text/javascript"> 
function printpage() 
    { 
    window.print() 
    } 
</script> 
<?php 
echo "<table border='1' id= results> 
<tr> 
<th>FILEID</th> 
<th>Firstname</th> 
<th>Lastname</th> 
<th>Issue Date</th> 
<th>Interest Rate</th> 
<th>Terms</th> 
<th>Balance Outstanding</th> 
<th>Balance Outstanding</th> 
<th>New Loan</th> 
<th>Principal Repayment for $l_month</th> 
<th>Principal Repaid</th> 
<th>Balance Outstanding</th> 
<th>Interest Payment for $l_month </th> 
<th>INTEREST ACCUMULATED DURING FINNANCIAL YEAR</th> 
</tr>"; 

while($row = mysql_fetch_array($result)) 
    { 


    echo "<tr>"; 

    echo "<td>" . $row['app_file_id'] . "</td>"; 
    echo"<td>". $row['app_fname']."</td>"; 
    echo"<td>". $row['app_lname']."</td>"; 
    echo"<td>". $row['commit_date'] ."</td>"; 
    echo"<td>". $row['computer_interest'] ."</td>"; 
    echo"<td>". $row['loan_life'] ."</td>"; 
    echo"<td>". $row['avg(app_ln_amnt)'] ."</td>"; 
    echo"<td>". $row['Balance Outstanding'] ."</td>"; 
    echo"<td>". $row['New Loan'] ."</td>"; 
    echo"<td>". $row['SUM(r.receipt_on_principal)'] ."</td>"; 
    echo"<td>". $row['Principal Repaid'] ."</td>"; 
    echo"<td>". $row['avg(app_amnt_owed)'] ."</td>";  
    echo"<td>". $row['SUM(r.receipt_on_interest)'] ."</td>"; 
    echo"<td>". $row['Interest Accumilated'] ."</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 
echo "<input type=\"button\" value=\"Print this page\" onclick=\"printpage()\" />"; 
?> 

をご希望の場合、ユーザは、この文書を開いているときに体内でのonloadイベントに関数を使用することができます上のプリンタがオンになります。

<body onload="printpage()"> 

幸運:)

+0

まだテーブルのPHPコンテンツを印刷していません:( – dames

4

PHPは、ブラウザにイベントを送信しません。あなたはJavascriptでそれを行うことができます。あなたのhtmlにこれを追加印刷しない他のすべてのものを非表示にするには

<input type="button" onclick="window.print()" value="Print Table" />

<style media="printer"> 
     .noprint * { 
      display:none; 
     } 

そして、親要素にCSSクラスNOPRINTを割り当てます印刷したくない。

テストしたが、これはあまりにも仕事ができるない:

body { 
    visibility: hidden; 
} 
.printthis { 
    visibility: visible; 
} 

を、クラスprintthisので、表だけが印刷されますあなたのテーブルを与えます。

+0

PHPのデータはまだ印刷されていません:( – dames

+0

あなたは変更されたPHPスクリプトを今投稿できますか? ) –

+0

@PierreGeier:これを試してもうまくいかなかったので、このHTMLページや作業用のHTMLページのフルスクリプトを投稿できますか? –

関連する問題