简体   繁体   English

通过Php和getcsv在HTML表中显示的特定列

[英]Specific Columns shown in HTML table via Php and getcsv

I'm just getting into php, html etc and am trying to resolve an issue at work. 我只是进入php,html等,并试图解决工作中的问题。 Please be patient with my lack of experience. 请耐心等待我缺乏经验。

I have a csv file, TEST2.csv. 我有一个csv文件TEST2.csv。 it is as follows advisor,guest,stockNumber,part,qty,partnote1,partnote2,status that I am putting on a webpage so that our staff can select their advisor number and see the status of their parts. 我在网页上输入的advisor,guest,stockNumber,part,qty,partnote1,partnote2,status ,以便我们的员工可以选择其顾问编号并查看零件的状态。 The report we export from our system is in csv and has columns that I do not want to show on this report. 我们从系统中导出的报告在csv中,并且包含我不想在此报告中显示的列。 (before I hear I should learn another format to display this, I know, Im under a time constraint and need something quick and rudimentary for now) (在我听说我应该学习另一种格式来显示此信息之前,我知道,Im在时间限制下,现在需要快速且基本的内容)

Everything works well but it does not show column 7, only up to 4. I want it to skip 5,6 Here's the monster i've created: 一切正常,但它不显示第7列,最多显示4。我希望它跳过5,6这是我创建的怪物:

<table id="demo">

<tbody>
<?php
$fp = fopen ( "TEST2.csv" , "r" );
    $wantedColumns = array(0,1,2,3,4,7);
while (( $data = fgetcsv ( $fp , 1000 , "," )) !== FALSE ) {

    $i = 0;
    echo "<tr>";
    foreach($data as $row) {
if (!in_array($i,$wantedColumns)) continue;
       echo "<td>" . $row . "</td>";
       $i++ ;
    }
    echo "/<tr>";
}
fclose ( $fp );
?>

` `

Any help would be greatly appreciated! 任何帮助将不胜感激!

Using simple array syntax with [index] your code will be: 使用带有[index]简单数组语法,您的代码将是:

$fp = fopen ( "TEST2.csv" , "r" );
while (( $data = fgetcsv ( $fp , 1000 , "," )) !== FALSE ) {
    echo "<tr>";
    echo "<td>" . $data[0] . "</td>";
    echo "<td>" . $data[1] . "</td>";
    echo "<td>" . $data[2] . "</td>";
    echo "<td>" . $data[3] . "</td>";
    echo "<td>" . $data[4] . "</td>";
    echo "<td>" . $data[7] . "</td>";
    echo "/<tr>";
}
fclose ( $fp );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM