2012-01-22 17 views
1

これは私の問題です。私はテーブルの内容だけをバッファリングすることができますが、ヘッダーはバッファできないようにします。 PHPの出力バッファリングを一時停止して、テーブルヘッダーのバッファリングをスキップして、実際のコンテンツの先頭で再開することは可能ですか?ヘッダ出力バッファをPHPで一時停止

<table> 
<tr> 
    <th>Account</th> 
    <th>Quarter</th> 
    <th>Amount</th> 
</tr> 
<?php 
ob_start(); 
echo "table data"; 
ob_end_flush(); 
+2

:あなただけの文字列をキャプチャせずにフラッシュするつもりなら、あなたにも、最初の場所でバッファリングしない場合がありますので、それはまた、愚かなのか? –

+0

バッファリングテーブルのポイントは何ですか? –

+0

@ Col.Shrapnelテーブルの先頭にバッファリングするものがあります。また、テーブルのタグの前にバッファリングしないと、実際にはデータがテーブルとして出力されません。 –

答えて

2

<?php ob_start(); ?> 
<table> 
<tr> 
    <th>Account</th> 
    <th>Quarter</th> 
    <th>Amount</th> 
</tr> 
    <?php 
    foreach($tc_item as $v){ 


    if($v->dbl_amt != 0){ 
    ?> 
    <tr> 
    <!-- Nature of Collection --> 
     <td id="nature"><?php echo $v->strDescription; ?></td> 
    <!-- Account Code -->  
     <td id="account"><?php echo $v->str_details; ?></td> 
    <!-- Amount --> 
     <td id="amount"><?php echo number_format($v->dbl_amt,2, '.', ''); ?></td> 

    </tr> 
    <?php } ?> 
    <?php } ?> 

</table> 
<?php 
$_SESSION['or_details'] = ob_get_contents(); 
?> 
+0

現在開かれているバッファをすべてフラッシュするall_obs_end_flushはありますか? – Pacerier

+0

'while(ob_get_level())ob_end_flush();' –

+0

@ .Francis Thanks =) – Pacerier

0

スタートバッファリングあなたはそれをバッファリングしていない、テーブル全体をバッファリングしたくない場合は、次の

<table> 
    <thead></thead> 
    <?php ob_start();?> 
    <tbody></tbody> 
    <?php $tbody = ob_get_flush(); ?> 
</table> 

あなたがバッファリングしたい場合テーブル全体を別々にしたい場合は、別のレベルのバッファリングを追加してください。

<?php ob_start();?> 
<table> 
    <thead></thead> 
    <?php ob_start();?> 
    <tbody></tbody> 
    <?php $tbody = ob_get_flush(); ?> 
</table> 
<?php $table = ob_get_clean(); ?> 

また、新しいバッファを作成せずに現在のバッファをフラッシュすることもできます。私はこれをお勧めしませんので、あなたのコードに従うことが難しくなります。 `のob_start()`ダウンヘッダーの過去を動かさないのはなぜ

<?php ob_start()?> 
<table> 
    <thead></thead> 
    <?php ob_flush();?> 
    <tbody></tbody> 
    <?php $tbody = ob_get_contents(); // only contains output since last flush ?> 
</table> 
<?php ob_end_flush(); ?> 
関連する問題