By using DISTINCT we can get unique classes from our student table .
<?php
$my_conn = new PDO('sqlite:my_student.sqlite3');
// Set errormode to exceptions
$my_conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$sql="SELECT DISTINCT(class) as class FROM student ";
echo "<table>";
foreach ($my_conn->query($sql) as $row) {
echo "<tr ><td>$row[class]</td></tr>";
}
echo "</table>";
?>
Output
Four
Three
Five
Six
Seven
Nine
Eight
Using DISTINCT query we can collect unique classes and populate a drop down list box as options. User can select one of the option from the pull down list box.
$sql="SELECT DISTINCT(class) as class FROM student ";
echo "<SELECT name=class>";
foreach ($my_conn->query($sql) as $row) {
echo "<option value='$row[class]'>$row[class]</option>";
}
echo "</SELECT>";