2013-01-15 3 views
0

내 루프를 통합하여 CSV로 내보내려면 어떻게해야합니까?CSV 파일 다운로드 용 내보내기 내보내기

<?php $answers = new WP_Query(array('cat' => 25, 'order' => 'DESC')); ?> 
<table width="100%" border="1" cellspacing="1" cellpadding="1"> 
     <tr> 
     <td valign="top">Name</td> 
     <td valign="top">Submission/production title</td> 
     <td valign="top">Performance space</td> 
     </tr> 
<?php if ($answers->have_posts()) : while ($answers->have_posts()) : $answers->the_post(); ?> 
     <tr> 
     <td><?php echo the_title(); ?></td> 
     <td><?php echo the_field('submit_submission_production_title'); ?></td> 
     <td><?php echo the_field('submit_performance_space'); ?></td> 
     </tr> 
    <?php endwhile; ?> 
    </table>      
<?php endif; ?> 

어떻게 fputcsv 이것을 통합 할 수 ?

<?php 
$list = array (
    'aaa,bbb,ccc,dddd', 
    '123,456,789', 
    '"aaa","bbb"' 
); 

$fp = fopen('file.csv', 'w'); 

foreach ($list as $line) { 
    fputcsv($fp, split(',', $line), ',', '&quot;'); 
} 
fclose($fp); 
?> 

답변

1
먼저

, the_titlethe_field * 스스로 echo기능, 당신은 echo the_title() 필요하지 않습니다.

*이것은 고급 사용자 지정 필드에서 온 것으로 가정합니다.

그냥 같은 배열 구축이에 대한

$answers = new WP_Query(array('cat' => 25, 'order' => 'DESC')); 
if ($answers->have_posts()) { 
    $list = array('Name,Submission/production title,Performance space'); 
    while ($answers->have_posts()) { 
     $title = get_the_title(); 
     $field1 = get_field('submit_submission_production_title'); 
     $field2 = get_field('submit_performance_space'); 
     $list[] = $title . ',' . $field1 . ',' . $field2; 

     // IF ENCLOSING DOUBLE QUOTES ARE NEEDED 
     // $list[] = '"' . $title . '","' . $field1 . '","' . $field2 . '"'; 
    } 
} 
+0

감사합니다, 나는 그것을 갈 줄 것입니다. 그런 다음 링크에 '파일 다운로드'라고 말하면 어떻게 CSV로 저장할 수 있습니까? – Rob

+0

'fputcsv'와'fclose'를 어떻게 처리 할지는 모르겠지만, 꽤 쉽고 아마도이 거대한 저장소에서 Stack이라는 검색이 될 것입니다.) – brasofilo