PHP获取列中(不同)数据的数量

Hy!

How can I get number of distinct data from column 3 and 6 of my table in my PHP:

<?php

open text file (first row is of headers which are divided by ;)

$fp = fopen('C:\...\usedlicences.txt','r') or die("can't open file");

create table with border

echo "<table id='MyTable' border='1'>
";

create header row for table with headers

echo "<td><b>id</b><td><b>name</b></td><td><b>surname</b></td><td><b>address</b></td><td><b>state</b></td><td><b>phone</b></td><td><b>city</b></td><td><b>date</b></td><td><b>color</b></td>";                          
$length = 1000;
$delimiter = ";";      
$k=1;

from file create rows and populate them with data (skip first (header) row) and add first column where id of row is written

$csv_line = fgetcsv( $fp, $length, $delimiter); 
while($csv_line = fgetcsv( $fp, $length, $delimiter ) ) {
echo "<tr>";            
echo "<td>$k</td>";
$k++;   
for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
echo '<td>'.$csv_line[$i].'</td>';  
}
}
echo "<tr>";   
echo '</table>';
fclose($fp) or die("can't close file");
?>

for showing alert how much licences are used (all rows minus header row)

<script language="JavaScript">
var oRows = document.getElementById('MyTable').getElementsByTagName('tr');
var iRowCount = oRows.length-1;
alert('Licences used: ' + ((iRowCount)-1)+'!');
</script>

test.txt looks like:

id;name;surname;address;state;phone;city;date;color
1;John;Simts;Yellow 12;Greenik;1234567;Mannds;12/3/1234;blue    

Thanks, greetings

Inside your for loop place the following code:

if ($i==3) 
   $surname[$csv_line[$i]]++;
else if ($i==6)
   $phone[$csv_line[$i]]++;

Then number of distinct records for surnames (column 3) and phones (column 6) would be:

count($surname);
count($phone);

respectively.