Data listing

Below is my table:

id title data
1 A data1
2 A data2
3 B data3

My query:

<?php
$onlytitle= mysql_query(“SELECT title FROM table”);

while($result = mysql_fetch_array( $onlytitle ))
{
$title=$result[‘title’];
echo $result[‘title’];

$check = mysql_query("SELECT data FROM table where title=$title ");

 while($info = mysql_fetch_array( $check ))
  {
     echo $info['data'];&lt;br /&gt;
  };

};

?>

My result :

A
Data1
Data2
A
Data1
Data2
B
Data3

Why it repeat the same group ?
How to make it to display the same title first, follow by all the data than follow by the next title and all the data ?

You’ll want to remove the duplicates from the “SELECT title FROM table” query.

You can use the DISTINCT keyword for that.