PHP SQLite DISTINCT

SQLite

We will create the database and connection object.
$my_conn = new PDO('sqlite:my_student.sqlite3');
We will use $my_conn to execute our query.

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>";
Output is here



Download sample script for SQLite with instructions on how to use.

Check PHP pdo support for SQLite using phpinfo()

PHP SQLite PDO Functions


plus2net.com







Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer