Display Unique Values of datafile
Unique values in file novels.csv
with fieldname protagonist
.
Code : (for display purposes, some lines wrap. The ↵ character indicates it. The character is not part of the code)
$path_to_db_script = $_SERVER['DOCUMENT_ROOT']↵ . "/" . "db/pjjtextbase.php"; require $path_to_db_script; $novels = ptb_connect ('novels.csv'); echo "<p>Unique values in file <code>novels.csv</code>↵ with fieldname <code>protagonist</code>.</p>"; print_r (ptb_listUnique ($novels, 'protagonist'));
Output :
Array ( [0] => Bond, James [1] => Maigret, Jules [2] => Marple, Miss [3] => Parker Pyne, James [4] => Poirot, Hercule [5] => Satterthwaite, Mr )
And as a bonus the lowest and highest value of fieldname year
.
echo "<p>Lowest value of field <code>year</code> = "; echo ptb_min ($novels, 'year'); echo "</p>"; echo "<p>Highest value of field <code>year</code> = "; echo ptb_max ($novels, 'year'); echo "</p>";
Lowest value of field year
= 1920
Highest value of field year
= 1976
⇪ Feb 17 2021 06:30:59