2012-01-22 5 views
1

여기 내 문제가 있습니다. 테이블의 내용 만 버퍼링하고 헤더는 버퍼링하지 못하게하려고합니다. PHP에서 출력 버퍼링을 일시 중지하여 테이블 헤더에서 버퍼링을 건너 뛰고 실제 내용의 시작 부분에서 다시 시작할 수 있습니까? 당신은 전체 테이블을 버퍼링하지 않으려면 헤더 후PHP에서 출력 버퍼 일시 중지

<?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(); 
?> 
+2

왜()'아래 헤더 과거 '위한 ob_start를 이동하지? –

+0

버퍼링 테이블에서 어떤 점이 있습니까? –

+0

@ Col.Shrapnel 테이블의 상단에 버퍼를 더하기 테이블 데이터 앞에 버퍼를 두지 않으면 실제로 데이터가 테이블로 나오지 않습니다. –

답변

2

, 다음 버퍼하지 않습니다

<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(); ?> 

또는 새 버퍼를 만들지 않고 현재 버퍼를 플러시 할 수 있습니다. 코드를 따르기가 더 어려워지기 때문에이 방법을 권장하지 않습니다. 그것은 당신이 단지 문자열을 캡처하지 않고 세척 할 거라면 때문에, 당신은뿐만 아니라 처음에 버퍼하지 않을 수도 바보 :

<?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(); ?> 
+0

현재 열린 버퍼를 모두 플러시하는 all_obs_end_flush가 있습니까? – Pacerier

+0

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

+0

@ .Francis Thanks =) – Pacerier

0

시작 버퍼링

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