我目前正在使用这个脚本:
<?php function jj_readcsv($filename, $header=false) { $handle = fopen($filename, "r"); echo '<table>'; //display header row if true if ($header) {
$csvcontents = fgetcsv($handle);
echo '<tr>';
foreach ($csvcontents as $headercolumn) {
echo "<th>$headercolumn</th>";
}
echo '</tr>'; } // displaying contents while ($csvcontents = fgetcsv($handle)) {
echo '<tr>';
foreach ($csvcontents as $column) {
echo "<td>$column</td>";
}
echo '</tr>'; } echo '</table>'; fclose($handle); } jj_readcsv('partitiontable.csv',true);
?>
我有一个 8 列的 CSV 表。我想知道在进行查询时是否可以只获取列的元素。这是我的 CSV 的样子:
"HEMSI, Alberto",P_000001,P_1,Partition,169864,"Hemsi, Myriam","HEMSI, Alberto","Una matica de ruda",
"HEMSI, Alberto",P_000002,P_2,Partition,169865,"Hemsi, Myriam","HEMSI, Alberto","Ya salio de la mar",
这个想法是:查询一个值,例如:P_1 并得到结果:Una matica de ruda
对于每一行,当询问 P_1 获取第 8 列中的值时。P_2 也一样